rewirte with backward iteration