fix a bug triggered by the uninitialized root_ pointer
add some methods to make the code easier to understand