cleanup and refactor CWTrie