Fixed socket.io issues. Many functions still to be updated to socket.io