public Node<T> insert(T value) {
    Node<T> node = null;
    Node<T> parent = root;
    while (parent != null) {
      int delta = compare(parent.getValue(), value);
      if (delta < 0) {
        if (parent.getRight() == null) {
          node = createNewNode(value);
          parent.setRight(node);
          node.setParent(parent);
          parent = null;
        } else {
          parent = parent.getRight();
        }
      } else if (delta > 0) {
        if (parent.getLeft() == null) {
          node = createNewNode(value);
          parent.setLeft(node);
          node.setParent(parent);
          parent = null;
        } else {
          parent = parent.getLeft();
        }
      } else {
        return null;
      }
    }
    if (node == null) {
      node = createNewNode(value);
      root = node;
    }

    setColor(node, NodeColor.RED);
    fixAfterInsertion(node);
    size++;

    return node;
  }