public E remove(E e) {

		if (root == null)
			return null;

		JuzerBranch<E> target = getTarget(e);

		if (target == null)
			return null;

		JuzerBranch<E> parent = target.getParent();
		// System.out.println("Target:" + target.Data());

		if (parent != null) {

			if (target.Left() == null && target.Right() == null) {

				if (parent.Left() == null) {
					parent.setRight(null);
				} else if (parent.Right() == null) {
					parent.setLeft(null);
				} else if (parent.Left().Data().compareTo(e) == 0) {
					parent.setLeft(null);
				} else {
					parent.setRight(null);
				}
				target.setParent(null);
				return target.Data();

			}
			if (target.Right() == null) {
				JuzerBranch<E> left = target.Left();

				if (parent.Left() == null) {
					parent.setRight(left);
				} else if (parent.Right() == null) {
					parent.setLeft(left);
				} else if (parent.Left().Data().compareTo(e) == 0) {
					parent.setLeft(left);
				} else {
					parent.setRight(left);
				}

				left.setParent(parent);
				target.setParent(null);
				return target.Data();
			}
			if (target.Left() == null) {
				JuzerBranch<E> right = target.Right();

				if (parent.Left() == null) {
					parent.setRight(right);
				} else if (parent.Right() == null) {
					parent.setLeft(right);
				} else if (parent.Left().Data().compareTo(e) == 0) {
					parent.setLeft(right);
				} else {
					parent.setRight(right);
				}

				right.setParent(parent);
				target.setParent(null);
				return target.Data();
			}
			JuzerBranch<E> next = getLeftMost(target.Right());

			if (parent.Left() == null) {
				parent.setRight(next);
			} else if (parent.Right() == null) {
				parent.setLeft(next);
			} else if (parent.Left().Data().compareTo(e) == 0) {
				parent.setLeft(next);
			} else {
				parent.setRight(next);
			}

			target.setParent(null);
			return target.Data();
		} else {

			if (root.Left() == null && root.Right() == null) {
				root = null;
				return target.Data();
			}

			else if (target.Right() == null) {
				root.Left().setParent(null);
				root = root.Left();
				return target.Data();
			} else if (target.Left() == null) {

				root.Right().setParent(null);
				root = root.Right();

				return target.Data();
			}
			JuzerBranch<E> next = getLeftMost(target.Right());

			if (next != target.Right()) {

				next.getParent().setLeft(next.Right());
				next.Right().setParent(next.getParent());
				next.setParent(null);
				next.setLeft(target.Left());
				next.setRight(target.Right());

			} else {
				next.setParent(parent);
				next.setLeft(target.Left());

			}

			target.Left().setParent(next);
			target.Right().setParent(next);
			root = next;
			return target.Data();
		}

	}