Fix bugs in pagination.