mangled the sort algorithm