Fix foreach loop