Improved trie code