[#5699] don't clobber the sort_key if it's in the query
[#5699] cleanup of unused untested util functions