Fixing smart_sort