refactored using level-trie