free function presorting