replaced for loop with range-based for