refactor main method