modified to use TreeWalker