code reorg and refactoring for output in preparation for more aggressive caching