refactoring main method