complete the pagination function