Tree structure establishment and traversal