fix foreach loops