Almost 600 lines of code for a little bit of fine grained controlis the wrong tradeoff. Please find a cheaper way to do this.