Factor out Trie and improve use of the partial flag