move disconnect to unload event