Refactor websocket