Use range-based for loops and const-correct a few things.