Continuation of issue #335, fixed the remaining for-each instances and turned them into regular for loops.