migration to socket.io, cleaned up the code a bit