refactored defintion tree with visitor pattern