Extract TreeNode class to lib/