Integrate HeapEnv and various bug fixes.