trie classes refactoring and fixes