improved code in WebSocketStream