Hoist a loop outside, maintain some state instead