Massive code refactoring.