Refactor socket.io disconnect logic