refactoring for socket.io