Replace for loops with forEach