Sorting works, but the building of a heap is incomplete