simplify a loop