Refactor WebSocket object