Removing globals from for loops