Simplify some loops