Code reorg and cleanup