wrote function to free the trie