Fix exception when sorting data subsets