Fix a bug returning wrong count value.