What does this loop do? What is the algorithm? Why are original host ids needed as part of the algorithm?