Refactoring pagination