minor optimization on heapsort function