refactored remove operation for Trie