Updated for loops to use c++11 ranged for.