Refactor code into a main method