implement paging and refactoring