added tree traversal helper