Added code to try and prevent common websocket errors