Heap sort plus some improvements