heap_lastp

I just tried to update heap_lastp in the right places and then use that
to make sure we keep references in bounds. May be incomplete.