added check for unsaved changes