Corrected sorting and pageing