     guard case let .Node(_, l, _, r) = self else { return 0 }
     return 1 + l.count + r.count
   }
-  
-  public func underestimateCount() -> Int {
-    return 0
-  }
-  
+}
+
+// MARK: Balance
+
+extension Tree {
   internal var isBalanced: Bool {
     switch balance {
     case .Balanced: return true

      return .Node(.R, .Node(.B,a,x,b),y,.Node(.B,c,z,d))
    default:
      return self
    }
  }
  
  private func cont(x: Element, _ p: Element) -> Bool {
    guard case let .Node(_, l, y, r) = self else { return x == p }
    return x < y ? l.cont(x, p) : r.cont(x, y)
  }
  
  /**
  Returns `true` iff `self` contains `x`
  
  - Complexity: O(*log n*)
  */
  
  public func contains(x: Element) -> Bool {
    guard case let .Node(_, l, y, r) = self else { return false }
    return x < y ? l.contains(x) : r.cont(x, y)
  }

  
  private func ins(x: Element) -> Tree {
    guard case let .Node(c, l, y, r) = self else { return Tree(x, color: .R) }
    if x < y { return Tree(y, color: c, left: l.ins(x), right: r).balL() }
    if y < x { return Tree(y, color: c, left: l, right: r.ins(x)).balR() }
    return self
  }
  
  /**
  Inserts `x` into `self`
  
  - Complexity: O(*log n*)
  */
  
  public mutating func insert(x: Element) {
    guard case let .Node(_, l, y, r) = ins(x) else {
      preconditionFailure("ins should not return an empty tree")
    }
    self = .Node(.B, l, y, r)
  }
  
  /**
  Runs a `TreeGenerator` over the elements of `self`. (The elements are presented in
  order, from smallest to largest)
  */
  
  public func generate() -> TreeGenerator<Element> {
    return TreeGenerator(stack: [], curr: self)
  }
  
  /**
  Returns the smallest element in `self` if it's present, or `nil` if `self` is empty
  
  - Complexity: O(*log n*)
  */
  
  public func minElement() ->  Element? {
    switch self {
    case .Empty: return nil
    case .Node(_, .Empty, let e, _): return e
    case .Node(_, let l, _, _): return l.minElement()
    }
  }
  
  /**
  Returns the largest element in `self` if it's present, or `nil` if `self` is empty
  
  - Complexity: O(*log n*)
  */
  
  public func maxElement() -> Element? {
    switch self {
    case .Empty: return nil
    case .Node(_, _, let e, .Empty) : return e
    case .Node(_, _, _, let r): return r.maxElement()
    }
  }
  

Full documentation is available [here](http://oisdk.github.io/SwiftDataStructures/Enums/Tree.html).
*/

public enum Tree<Element: Comparable> : Equatable {
  case Empty
  indirect case Node(Color,Tree<Element>,Element,Tree<Element>)
}

/// :nodoc:

public func ==<E : Comparable>(lhs: Tree<E>, rhs: Tree<E>) -> Bool {
  return lhs.elementsEqual(rhs)
}

// MARK: Initializers

extension Tree : ArrayLiteralConvertible {
  
  /// Create an empty `Tree`.
  
