pulled out lots of verbose code into stand-alone modules