Updated the pagination function to display correctly