added onbeforeunload function