fixed bugs in paging logic. sorting added