changed forEach to for loops