converted more loops to use auto