added trie and selection logic