Finish the function of count api.