refactor to support paging