public V remove(K key) {
        if (root == null) {
            return null;
        }
        if (root.key.compareTo(key) == 0) {
            V temp = root.value;
            if (root.right == null) {
                root = root.left;
            } else if (root.left == null) {
                root = root.right;
            } else if (root.left.right == null) {
                root.left.right = root.right;
                root = root.left;
            } else {
                BinaryTreeNode<K, V> rightChild = root.left.popRightmostChild();
                rightChild.left = root.left;
                rightChild.right = root.right;
                root = rightChild;
            }
            return temp;
        }
        return root.remove(key);
    }