refactored classic for loops to forEach loops