Merges Philipp modification for window unload event.