Refactored socket.io code in the stream module