Convert some for loops into forEach calls