working function for finding words in trie