Fixed sorting function not using name at last resort