working on ternary tree