Allow the user to cancel. Refactor to allow easier integration with other programs.