new sorting code