added websocket connection
changed sequence of events