Modified sorting and its tests