Can this be refactored to use parser.tree.struct.walk?