fix count infinite loop

closes #367