edited pagination functionality