Fix MiscSorter undef index and query error