protected Node put(T elem, Node x) {

		if (x == null) {
			x = new Node();
			x.entity = elem;
			x.count = 1;
			x.isRed = true;

		} else {

			int compareResult = elem.compareTo(x.entity);

			if (compareResult < 0) {
				x.left = put(elem, x.left);
			} else if (compareResult > 0) {
				x.right = put(elem, x.right);
			}

			if (x.right.isRed && !x.left.isRed) {
				x = turnLeft(x);
			}

			if (x.left.isRed && x.left.left.isRed) {
				x = turnRight(x);
			}

			if (x.left.isRed && x.right.isRed) {
				flipColors(x);
			}

			x.count = 1 + size(x.left) + size(x.right);
		}

		return x;

	}