fix count infinite loop

closes #367
Merge pull request #368 from epeli/count-loop

fix count infinite loop