Changed beforeunload to unload()