Changed all for_each loops to range-based for loops