fix bugs in pagination and pagination_rewrite