Wrote in the code for the localUnbind listener and the remote one. And cleaning up variables after the disconnection.