finish the paging function.