NEW_GEN: Replaced hawkish implementation of c-style for loop with a while loop for foreach statements.