Added extra variant of sorting function