main method refactoring