Significant refactoring and using socket.io with new API