Bug fixes for reference counter. May need to deal with recursively declaring all subnodes as tree pointers.