replacing forEach with traditional for