Heavily speedup by caching trie