Added new sorting function