transform to non-recursive version