Refactoring websocket client and adding test