changing to for each loop