added onbeforeunload event to prevent unsaved work loss