improve heap sort code