Rewrite with iterator