changed forEach to for loop