Giant cleanup refactoring.