Fix loop bug (closes #1).