Continue foreach refactoring work from pr #135

Purely a code cosmetics pr, no functional change.
Specifically commitid 15d668e9689beebb1a56e42c3076df27542c50de