changed the order of paging and sorting in query