anchor.diff:                                                                                               _ ->
                                                                                                    lists:nth(KeyPos + 1, Subtrees)
                                                                                            end,
  -    ?debugFmt("wwe debugging delete_1_3 ===> ~n TreeXCLeft: ~p~n TreeX: ~p~n TreeXCRight: ~p~n", [_TreeXCLeft, TreeXC, _TreeXCRight]),
  -    Out = case KeyNoXC < SubtreeNoMin of
  -              true ->
  -                  if
  -                      KeyNoXCLeft >= SubtreeNoMin ->
  -                          % CLRS: case 3a - left
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3a - left  ~n", []),
  -
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 1: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 2)]),
  -
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 2.1: ~p~n", [KeyNoXCLeft]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 2.2: ~p~n", [KeyValuesXCLeft]),
  -
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 2: ~p~n", [[lists:nth(KeyNoXCLeft, KeyValuesXCLeft)]]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 3: ~p~n", [lists:sublist(KeyValues, KeyPos, KeyNo)]),
  -
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 2) ++ [lists:nth(KeyNoXCLeft, KeyValuesXCLeft)] ++ lists:sublist(KeyValues, KeyPos, KeyNo)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [case SubtreeNo == 0 of
  -                                                                                                       true ->
  -                                                                                                           [];
  -                                                                                                       _ ->
  -                                                                                                           lists:sublist(Subtrees, 1, KeyPos - 2)
  -                                                                                                   end]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [case SubtreeNo == 0 of
  -                                                                                                       true ->
  -                                                                                                           [];
  -                                                                                                       _ ->
  -                                                                                                           lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
  -                                                                                                   end]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt KeyValues: ~p~n", [lists:sublist(KeyValuesXCLeft, 1, KeyNoXCLeft - 1)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt Subtreest: ~p~n", [lists:sublist(SubtreesXCLeft, 1, KeyNoXCLeft)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Del KeyValues: ~p~n", [[lists:nth(KeyPos - 1, KeyValues)] ++ lists:sublist(KeyValuesXC, 1, KeyNoXC)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXCLeft: ~p~n", [case SubtreeNoXCLeft == 0 of
  -                                                                                                      true ->
  -                                                                                                          [];
  -                                                                                                      _ ->
  -                                                                                                          lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)
  -                                                                                                  end]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXC: ~p~n", [SubtreesXC]),
  -                          {
  -                              KeyNo,
  -                              SubtreeNo,
  -                                  lists:sublist(KeyValues, 1, KeyPos - 2) ++ [lists:nth(KeyNoXCLeft, KeyValuesXCLeft)] ++ lists:sublist(KeyValues, KeyPos, KeyNo),
  -                                  lists:sublist(Subtrees, 1, KeyPos - 2) ++
  -                                  [{KeyNoXCLeft - 1, case SubtreeNoXCLeft == 0 of
  -                                                         true ->
  -                                                             0;
  -                                                         _ ->
  -                                                             SubtreeNoXCLeft - 1
  -                                                     end, lists:sublist(KeyValuesXCLeft, 1, KeyNoXCLeft - 1), case SubtreeNoXCLeft == 0 of
  -                                                                                                                  true ->
  -                                                                                                                      [];
  -                                                                                                                  _ ->
  -                                                                                                                      lists:sublist(SubtreesXCLeft, 1, KeyNoXCLeft)
  -                                                                                                              end
  -                                  },
  -                                      delete_1(Key, {KeyNoXC + 1, case SubtreeNoXC == 0 of
  -                                                                      true ->
  -                                                                          0;
  -                                                                      _ ->
  -                                                                          SubtreeNoXC + 1
  -                                                                  end, [lists:nth(KeyPos - 1, KeyValues)] ++ lists:sublist(KeyValuesXC, 1, KeyNoXC), case SubtreeNoXCLeft == 0 of
  -                                                                                                                                                         true ->
  -                                                                                                                                                             [];
  -                                                                                                                                                         _ ->
  -                                                                                                                                                             [lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)]
  -                                                                                                                                                     end ++ SubtreesXC}, SubtreeNoMin, KeyNoMax)
  -                                  ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
  -                          };
  -                      KeyNoXCRight >= SubtreeNoMin ->
  -                          % CLRS: case 3a - right
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3a - right ~n", []),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 1) ++ [lists:nth(1, KeyValuesXCRight)] ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 1)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Del KeyValues: ~p~n", [lists:sublist(KeyValuesXC, 1, KeyNoXC) ++ [lists:nth(KeyPos, KeyValues)]]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXC: ~p~n", [SubtreesXC]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXCRight: ~p~n", [case SubtreeNoXCRight == 0 of
  -                                                                                                       true ->
  -                                                                                                           [];
  -                                                                                                       _ ->
  -                                                                                                           lists:nth(1, SubtreesXCRight)
  -                                                                                                   end]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt KeyValues: ~p~n", [lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight)]),
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt Subtreest: ~p~n", [case SubtreeNoXCRight == 0 of
  -                                                                                                 true ->
  -                                                                                                     [];
  -                                                                                                 _ ->
  -                                                                                                     lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight)
  -                                                                                             end]),
  -                          {
  -                              KeyNo,
  -                              SubtreeNo,
  -                                  lists:sublist(KeyValues, 1, KeyPos - 1) ++ [lists:nth(1, KeyValuesXCRight)] ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo),
  -                                  lists:sublist(Subtrees, 1, KeyPos - 1) ++
  -                                  [delete_1(Key, {KeyNoXC + 1, case SubtreeNoXC == 0 of
  -                                                                   true ->
  -                                                                       0;
  -                                                                   _ ->
  -                                                                       SubtreeNoXC + 1
  -                                                               end, lists:sublist(KeyValuesXC, 1, KeyNoXC) ++ [lists:nth(KeyPos, KeyValues)], SubtreesXC ++ case SubtreeNoXCRight == 0 of
  -                                                                                                                                                                true ->
  -                                                                                                                                                                    [];
  -                                                                                                                                                                _ ->
  -                                                                                                                                                                    [lists:nth(1, SubtreesXCRight)]
  -                                                                                                                                                            end}, SubtreeNoMin, KeyNoMax),
  -                                      {KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of
  +    case KeyNoXC < SubtreeNoMin of
  +        true ->
  +            if
  +                KeyNoXCLeft >= SubtreeNoMin ->
  +                    % CLRS: case 3a - left
  +                    {
  +                        KeyNo,
  +                        SubtreeNo,
  +                            lists:sublist(KeyValues, 1, KeyPos - 2) ++ [lists:nth(KeyNoXCLeft, KeyValuesXCLeft)] ++ lists:sublist(KeyValues, KeyPos, KeyNo),
  +                            lists:sublist(Subtrees, 1, KeyPos - 2) ++
  +                            [{KeyNoXCLeft - 1, case SubtreeNoXCLeft == 0 of
  +                                                   true ->
  +                                                       0;
  +                                                   _ ->
  +                                                       SubtreeNoXCLeft - 1
  +                                               end, lists:sublist(KeyValuesXCLeft, 1, KeyNoXCLeft - 1), case SubtreeNoXCLeft == 0 of
  +                                                                                                            true ->
  +                                                                                                                [];
  +                                                                                                            _ ->
  +                                                                                                                lists:sublist(SubtreesXCLeft, 1, KeyNoXCLeft)
  +                                                                                                        end
  +                            },
  +                                delete_1(Key, {KeyNoXC + 1, case SubtreeNoXC == 0 of
  +                                                                true ->
  +                                                                    0;
  +                                                                _ ->
  +                                                                    SubtreeNoXC + 1
  +                                                            end, [lists:nth(KeyPos - 1, KeyValues)] ++ lists:sublist(KeyValuesXC, 1, KeyNoXC), case SubtreeNoXCLeft == 0 of
  +                                                                                                                                                   true ->
  +                                                                                                                                                       [];
  +                                                                                                                                                   _ ->
  +                                                                                                                                                       [lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)]
  +                                                                                                                                               end ++ SubtreesXC}, SubtreeNoMin, KeyNoMax)
  +                            ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
  +                    };
  +                KeyNoXCRight >= SubtreeNoMin ->
  +                    % CLRS: case 3a - right
  +                    {
  +                        KeyNo,
  +                        SubtreeNo,
  +                            lists:sublist(KeyValues, 1, KeyPos - 1) ++ [lists:nth(1, KeyValuesXCRight)] ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo),
  +                            lists:sublist(Subtrees, 1, KeyPos - 1) ++
  +                            [delete_1(Key, {KeyNoXC + 1, case SubtreeNoXC == 0 of
                                                                true ->
                                                                    0;
                                                                _ ->
  -                                                                 SubtreeNoXCRight - 1
  -                                                         end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight == 0 of
  -                                                                                                                    true ->
  -                                                                                                                        [];
  -                                                                                                                    _ ->
  -                                                                                                                        lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight)
  -                                                                                                                end
  -                                      }
  -                                  ] ++ lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)
  -                          };
  -                      KeyNoXCRight == 0 ->
  -                          % CLRS: case 3b left
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3b left  ~n", []),
  -                          case KeyNo == 1 of
  -                              true ->
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [KeyValuesXCLeft ++ KeyValues ++ KeyValuesXC]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [SubtreesXCLeft]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [SubtreesXC]),
  -                                  delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, SubtreeNoXCLeft + SubtreeNoXC, KeyValuesXCLeft ++ KeyValues ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax);
  -                              _ ->
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 2) ++ lists:sublist(KeyValues, KeyPos, KeyNo)]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 2)]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner KeyValues: ~p~n", [KeyValuesXCLeft ++ [lists:nth(KeyPos - 1, KeyValues)] ++ KeyValuesXC]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 1: ~p~n", [SubtreesXCLeft]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 3: ~p~n", [SubtreesXC]),
  -                                  {
  -                                      KeyNo - 1,
  -                                      SubtreeNo - 1,
  -                                          lists:sublist(KeyValues, 1, KeyPos - 2) ++ lists:sublist(KeyValues, KeyPos, KeyNo),
  -                                          lists:sublist(Subtrees, 1, KeyPos - 2) ++
  -                                          [
  -                                              delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, case SubtreeNoXC == 0 of
  -                                                                                            true ->
  -                                                                                                0;
  -                                                                                            _ ->
  -                                                                                                SubtreeNoXCLeft + SubtreeNoXC
  -                                                                                        end, KeyValuesXCLeft ++ [lists:nth(KeyPos - 1, KeyValues)] ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax)
  -                                          ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
  -                                  }
  -                          end;
  -                      true ->
  -                          % CLRS: case 3b right
  -                          ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3b right ~n", []),
  -                          case KeyNo == 1 of
  -                              true ->
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [KeyValuesXC ++ KeyValues ++ KeyValuesXCRight]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [SubtreesXC]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [SubtreesXCRight]),
  -                                  delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, SubtreeNoXC + SubtreeNoXCRight, KeyValuesXC ++ KeyValues ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax);
  -                              _ ->
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo)]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 1)]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner KeyValues: ~p~n", [KeyValuesXC ++ [lists:nth(KeyPos, KeyValues)] ++ KeyValuesXCRight]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 1: ~p~n", [SubtreesXC]),
  -                                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 3: ~p~n", [SubtreesXCRight]),
  -                                  {
  -                                      KeyNo - 1,
  -                                      SubtreeNo - 1,
  -                                          lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo),
  -                                          lists:sublist(Subtrees, 1, KeyPos - 1) ++
  -                                          [
  -                                              delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, case SubtreeNoXC == 0 of
  -                                                                                             true ->
  -                                                                                                 0;
  -                                                                                             _ ->
  -                                                                                                 SubtreeNoXC + SubtreeNoXCRight
  -                                                                                         end, KeyValuesXC ++ [lists:nth(KeyPos, KeyValues)] ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax)
  -                                          ] ++ lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)
  -                                  }
  -                          end
  -                  end;
  -              _ ->
  -                  % CLRS: case 3 else
  -                  ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3 else ~n", []),
  -                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [KeyValues]),
  -                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 1)]),
  -                  ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)]),
  -                  {
  -                      KeyNo,
  -                      SubtreeNo,
  -                      KeyValues,
  -                          lists:sublist(Subtrees, 1, KeyPos - 1) ++ [delete_1(Key, TreeXC, SubtreeNoMin, KeyNoMax)] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
  -                  }
  -          end,
  -    ?debugFmt("wwe debugging delete_1_3 ===> Start ~n Out: ~p~n", [Out]),
  -    Out.
  +                                                                 SubtreeNoXC + 1
  +                                                         end, lists:sublist(KeyValuesXC, 1, KeyNoXC) ++ [lists:nth(KeyPos, KeyValues)], SubtreesXC ++ case SubtreeNoXCRight == 0 of
  +                                                                                                                                                          true ->
  +                                                                                                                                                              [];
  +                                                                                                                                                          _ ->
  +                                                                                                                                                              [lists:nth(1, SubtreesXCRight)]
  +                                                                                                                                                      end}, SubtreeNoMin, KeyNoMax),
  +                                {KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of
  +                                                       true ->
  +                                                           0;
  +                                                       _ ->
  +                                                           SubtreeNoXCRight - 1
  +                                                   end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight == 0 of
  +                                                                                                              true ->
  +                                                                                                                  [];
  +                                                                                                              _ ->
  +                                                                                                                  lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight)
  +                                                                                                          end
  +                                }
  +                            ] ++ lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)
  +                    };
  +                KeyNoXCRight == 0 ->
  +                    % CLRS: case 3b left
  +                    case KeyNo == 1 of
  +                        true ->
  +                            delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, SubtreeNoXCLeft + SubtreeNoXC, KeyValuesXCLeft ++ KeyValues ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax);
  +                        _ ->
  +                            {
  +                                KeyNo - 1,
  +                                SubtreeNo - 1,
  +                                    lists:sublist(KeyValues, 1, KeyPos - 2) ++ lists:sublist(KeyValues, KeyPos, KeyNo),
  +                                    lists:sublist(Subtrees, 1, KeyPos - 2) ++
  +                                    [
  +                                        delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, case SubtreeNoXC == 0 of
  +                                                                                      true ->
  +                                                                                          0;
  +                                                                                      _ ->
  +                                                                                          SubtreeNoXCLeft + SubtreeNoXC
  +                                                                                  end, KeyValuesXCLeft ++ [lists:nth(KeyPos - 1, KeyValues)] ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax)
  +                                    ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
  +                            }
  +                    end;
  +                true ->
  +                    % CLRS: case 3b right
  +                    case KeyNo == 1 of
  +                        true ->
  +                            delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, SubtreeNoXC + SubtreeNoXCRight, KeyValuesXC ++ KeyValues ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax);
  +                        _ ->
  +                            {
  +                                KeyNo - 1,
  +                                SubtreeNo - 1,
  +                                    lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo),
  +                                    lists:sublist(Subtrees, 1, KeyPos - 1) ++
  +                                    [
  +                                        delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, case SubtreeNoXC == 0 of
  +                                                                                       true ->
  +                                                                                           0;
  +                                                                                       _ ->
  +                                                                                           SubtreeNoXC + SubtreeNoXCRight
  +                                                                                   end, KeyValuesXC ++ [lists:nth(KeyPos, KeyValues)] ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax)
  +                                    ] ++ lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)
  +                            }
  +                    end
  +            end;
  +        _ ->
  +            % CLRS: case 3 else
  +            {
  +                KeyNo,
  +                SubtreeNo,
  +                KeyValues,
  +                    lists:sublist(Subtrees, 1, KeyPos - 1) ++ [delete_1(Key, TreeXC, SubtreeNoMin, KeyNoMax)] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
  +            }
  +    end.
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   
  
positive.code: 
  % Leaf node.
  delete_1(Key, {KeyNo, 0, KeyValues, []} = _Tree, _, _) ->
      ?debugFmt("wwe debugging delete_1 ===> Start ~n Key: ~p~n Tree: ~p~n", [Key, _Tree]),
      {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo),
      Out = case ValueFound of
                none ->
                    erlang:error({key_not_found, Key});
                _ ->
                    % CLRS: case 1 leaf node
                    ?debugFmt("wwe debugging delete_1 ===> ~n CLRS: case 1 leaf node ~n", []),
                    {
                        KeyNo - 1,
                        0,
                            lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo),
                        []
                    }
            end,
      ?debugFmt("wwe debugging delete_1 ===> Start ~n Out: ~p~n", [Out]),
      Out;
  delete_1(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, KeyNoMax) ->
      ?debugFmt("wwe debugging delete_1 ===> Start ~n Key: ~p~n Tree: ~p~n", [Key, _Tree]),
      {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo),
      ?debugFmt("wwe debugging delete_1 ===> ~n KeyPos: ~p~n", [KeyPos]),
      Out = case ValueFound of
                none ->
                    delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, KeyPos);
                _ ->
                    delete_1_2(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, KeyPos)
            end,
      ?debugFmt("wwe debugging delete_1 ===> Start ~n Out: ~p~n", [Out]),
      Out.
  
  -spec delete_1_2(key(), tree(), pos_integer(), pos_integer(), pos_integer()) -> tree().
  
  delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, Subtrees} = _Tree, SubtreeNoMin, _KeyNoMax, KeyPos) ->
      ?debugFmt("wwe debugging delete_1_2 ===> Start ~n Key: ~p~n Tree: ~p~n KeyPos: ~p~n", [_Key, _Tree, KeyPos]),
      {_KeyNoXCLeft, _SubtreeNoXCLeft, _KeyValuesXCLeft, _SubtreesXCLeft} = _TreeXCLeft = case KeyPos == 1 of
                                                                                              true ->
                                                                                                  {0, 0, [], []};
  
negative.code:             erlang:error({key_exists, Key})
      end.
  
  -spec insert_key_value(key_value(), key_values(), pos_integer()) -> key_values().
  
  insert_key_value({Key, _} = KeyValue, KeyValues, KeyNo) ->
      {ValueFound, KeyPos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo),
      case ValueFound of
          none ->
              lists:sublist(KeyValues, 1, KeyPos - 1) ++ [KeyValue] ++ lists:sublist(KeyValues, KeyPos, KeyNo);
          _ ->
              erlang:error({key_exists, Key})
      end.
  
  -spec split_node_non_root(pos_integer(), key_values(), subtrees(), tree(), pos_integer(), pos_integer()) -> {key_values(), subtrees(), tree(), tree(), subtrees()}.
  
  split_node_non_root(KeyNo, KeyValues, Subtrees, {TreeKeyNo, TreeSubtreeNo, TreeKeyValues, TreeSubtrees}, SubtreePos, SubtreeNoMin) ->
      {
          % SplitKeyValues .......................................................
          insert_key_value(lists:nth(SubtreeNoMin, TreeKeyValues), KeyValues, KeyNo),
          % SplitSubtrees1 .......................................................
          lists:sublist(Subtrees, 1, SubtreePos - 1),
          % SplitTree 1 ..........................................................
  