added save before leave functionality