Functions for tree exploration and manipulation