refactor the main program