refactor iterator loop with foreach lamda