Refactored code into multiple tree and node types