Massive refactoring.