patricia trie works. Need to optimize code