refactor trie