refactored tree-logic code to be its own class.