Cleaning up main program logic