optimize the heap-sort again