massive code refactoring.