lots of cleanup and reorg