Completed word tree building logic