Fixed issue when WebSocket messages are not processed because OnOpen event fires after OnMessage.
Code optimizations, added more debug logging.