Fixed query paging and sorting issue