counting simulator bugfix and speedup