changed it to a foreach loop