Improve terneray heap, document index calculations