clean up iteration logic a bit