Heap fixes and unit test.