Converted the last loop to a C++11 Range based for loop