ternary tree insertion and removal