Refactored the pagination to make it slightly readable