Fix overwriting of counter variable.

Closes #16.