refactored creating websocket