Refactor socket.js