Traversing tree by iteration