fix a bug for counting