some refactoring on return values of several methods, and also add more assertion for type checking to make sure the heap is constructed as the way we want