Fixed iteration problem in Issue #169 and added tests.