Main refactoring