refactored prefixTrie to be cleaner and more consice