Fixes undefined loop variables (fixes #657)
Merge pull request #658 from csugden/patch-1

Fixes undefined loop variables (fixes #657)