Rewriting prefix tree from scratch.