massive code refactoring