Fix 'for each' bugs