Refactored WebSocket impl