Added a new sorting function