Large code refactoring