added the boolean to check whether data has been saved before exitting