If you just add the sessionId to the dictionary, the recursive call that happens in the next if block causes the first message it pulls off to be dropped. If you were to set registeredWorkerSessionId = sessionId it will skip the recursive call and return the new Worker object from the first message it sees.