Embarassingly massive refactoring.