Issue #139: Fix count and pagination.

can you explain the logic here please?