modernization: use range for loops in a few more places