Initial refactoring of websocket