rewrite using iterate