Refactoring websocket