Massive code refactoring after code review