iterator rewrite, to combine with first commit