refactoring pagination