Fix up a few bugs in the heap. Seems to be working now.