Cleans up websocket stuff, and adds error reporting.