Fix handling of case when totalCount is 0