refactor paginate