correcting foreach loops here