Avoid undefined behavior for removing elements that were not in the tree.