improve the sort algorithm