Refactored the pagination