Code cleanup and reorg.