main refactoring