simplify top level loop