rewrite some for loops to for-each style