Refactored the HeapSort class.