Further refactor: pass the pair object to iternext(), so that it only needs to fill in the yielded value when the iterator is still valid