Initial stab at WebSocket support
Refactor error handling