   defp node_delete(node, 0, hash, key) do
     pos = bucket_index(hash)
     case bucket_delete(elem(node, pos), key) do
-      { _, 0 }    -> { node, 0 }
-      { new, -1 } -> { set_elem(node, pos, new), -1 }
+      { _, value, 0 } -> { node, value, 0 }
+      { new, value, -1 } -> { set_elem(node, pos, new), value, -1 }
     end
   end
 
   defp node_delete(node, depth, hash, key) do
     pos = bucket_index(hash)
     case node_delete(elem(node, pos), depth - 1, bucket_next(hash), key) do
-      { _, 0 }    -> { node, 0 }
-      { new, -1 } -> { set_elem(node, pos, new), -1 }
+      { _, value, 0 } -> { node, value, 0 }
+      { new, value, -1 } -> { set_elem(node, pos, new), value, -1 }
     end
   end
 

  Returns the value under key from the dict as well as the dict without key.
  """
  def pop(dict, key, default // nil) do
    { get(dict, key, default), delete(dict, key) }
  end

  @doc """
  Deletes a value from the dict.
  """
  def delete(ordered(bucket: bucket, size: size) = dict, key) do
    case bucket_delete(bucket, key) do
      { _, 0 } ->
        dict
      { new_bucket, -1 } ->
        ordered(dict, size: size - 1, bucket: new_bucket)
    end
  end

  def delete(trie(root: root, size: size, depth: depth) = dict, key) do
    pos = bucket_hash(key)
    case node_delete(root, depth, pos, key) do
      { _, 0 } ->
        dict
      { root, -1 } ->
        if depth > 0 and trie(dict, :contract_on) == size do
          root = node_contract(root, depth, depth - 1)
          trie(dict,
            root: root,


  # Deletes a key from the bucket
  defp bucket_delete([{k,_}|_] = bucket, key) when key < k do
    { bucket, nil, 0 }
  end

  defp bucket_delete([{k,_}=e|bucket], key) when key > k do
    { rest, value, count } = bucket_delete(bucket, key)
    { [e|rest], value, count }
  end

  defp bucket_delete([{_,value}|bucket], _key) do
    { bucket, value, -1 }
  end

  defp bucket_delete([], _key) do
    { [], nil, 0 }
  end

  # Folds the bucket
