More refactoring; add iteration primitive.