inserted Dave Porter's sorting algorithm