fix a bug in counting function