Complete rewrite using socket.io for communication