moved the iterator keys lookup code out of the loop