Refactor main method