Refactoring main