Refactor exiting program