Fix foreach issue