add basic tree traversal, as well as parent and span index construction. some refactoring.