moved logic into the trie