Refactoring and added socket.io