Fixing inconsistent foreach style loops

probably more still lurking in the code