Refactoring and added socket.io on the server