public int createOrder(String contents) {
		contents = contents.replaceAll("[\t \n\r]", "");
		contents = contents.replaceAll("ee", "" + Math.E);
		contents = contents.replaceAll("pi", "" + Math.PI);
		String contentsStart = contents;
		System.out.println(contents);
		while (contents.matches(".*ln[(].*[)].*")) {
			String fun = "ln(";
			String subContents = contents.substring(contents.indexOf(fun) + fun.length(), getMatchingParenIndex(contents, contents.indexOf(fun) + fun.length()));
			int d = createOrder(subContents);
			contents = contents.replace(fun + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.LN, d, -1, d));
		}
		while (contents.matches(".*asin[(].*[)].*")) {
			String fun = "asin(";
			String subContents = contents.substring(contents.indexOf(fun) + fun.length(), getMatchingParenIndex(contents, contents.indexOf(fun) + fun.length()));
			int d = createOrder(subContents);
			contents = contents.replace(fun + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.ASIN, d, -1, d));
		}
		while (contents.matches(".*acos[(].*[)].*")) {
			String fun = "acos(";
			String subContents = contents.substring(contents.indexOf(fun) + fun.length(), getMatchingParenIndex(contents, contents.indexOf(fun) + fun.length()));
			int d = createOrder(subContents);
			contents = contents.replace(fun + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.ACOS, d, -1, d));
		}
		while (contents.matches(".*atan[(].*[)].*")) {
			String fun = "atan(";
			String subContents = contents.substring(contents.indexOf(fun) + fun.length(), getMatchingParenIndex(contents, contents.indexOf(fun) + fun.length()));
			int d = createOrder(subContents);
			contents = contents.replace(fun + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.ATAN, d, -1, d));
		}
		while (contents.matches(".*toRadians[(].*[)].*")) {
			String fun = "toRadians(";
			String subContents = contents.substring(contents.indexOf(fun) + fun.length(), getMatchingParenIndex(contents, contents.indexOf(fun) + fun.length()));
			int d = createOrder(subContents);
			contents = contents.replace(fun + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.TO_RADIANS, d, -1, d));
		}
		while (contents.matches(".*tan[(].*[)].*")) {
			String fun = "tan(";
			String subContents = contents.substring(contents.indexOf(fun) + fun.length(), getMatchingParenIndex(contents, contents.indexOf(fun) + fun.length()));
			int d = createOrder(subContents);
			contents = contents.replace(fun + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.TAN, d, -1, d));
		}
		while (contents.matches(".*cos[(].*[)].*")) {
			String fun = "cos(";
			String subContents = contents.substring(contents.indexOf(fun) + fun.length(), getMatchingParenIndex(contents, contents.indexOf(fun) + fun.length()));
			int d = createOrder(subContents);
			contents = contents.replace(fun + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.COS, d, -1, d));
		}
		while (contents.matches(".*sqrt[(].*[)].*")) {
			String subContents = contents.substring(contents.indexOf("sqrt(") + 5, getMatchingParenIndex(contents, contents.indexOf("sqrt(") + 5));
			int d = createOrder(subContents);
			contents = contents.replace("sqrt(" + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.SQRT, d, -1, d));
		}
		while (contents.matches(".*sin[(].*[)].*")) {
			String subContents = contents.substring(contents.indexOf("sin(") + 4, getMatchingParenIndex(contents, contents.indexOf("sin(") + 4));
			int d = createOrder(subContents);
			contents = contents.replace("sin(" + subContents + ")", "" + d);
			operations.add(new FunctionOperation(FunctionOperation.SIN, d, -1, d));
		}
		while (contents.matches(".*[(].*[)].*")) {
			int  i = contents.indexOf("(");
			String subContents = contents.substring(i + 1, getMatchingParenIndex(contents, i));
			System.out.println(contentsStart + ":" + subContents);
			int d = createOrder(subContents);
			if (contents.charAt(i- 1) == '-' && (contents.indexOf("(") < 2 || !contents.substring(i - 2).matches("[0-9xyz].*"))) {
				operations.add(new FunctionOperation(FunctionOperation.NEGATE, d, -1, d));
				contents = contents.replace("-(" + subContents + ")", "" + d);
			} else {
				contents = contents.replace("(" + subContents + ")", "" + d);
			}
		}
		//Now that all parens are gone, do the rest of PEMDAS (Exponents, Multiply, Divide, Add, Sub) 
		while (contents.contains("^")) {
			int index = contents.indexOf('^');
			String[] unfilteredHalves = new String[] {contents.substring(0, index), contents.substring(index + 1)};
			String number1 = getNumberFromEnd(unfilteredHalves[0]);
			String number2 = getNumberFromBeginning(unfilteredHalves[1]);
			int parsedNum1 = Integer.parseInt(number1);
			int parsedNum2 = Integer.parseInt(number2);
			contents = contents.replace(number1 + "^" + number2, "" + totalIndecies++);
			operations.add(new FunctionOperation(FunctionOperation.EXPONENT, parsedNum1, parsedNum2, totalIndecies - 1));
		}
		while (contents.contains("*") || contents.contains("/")) {
			String[] unfilteredHalves = contents.split("[*/]", 2);
			String number1 = getNumberFromEnd(unfilteredHalves[0]);
			String number2 = getNumberFromBeginning(unfilteredHalves[1]);
			int parsedNum1 = Integer.parseInt(number1);
			int parsedNum2 = Integer.parseInt(number2);
			if (contents.indexOf("*") != -1 && (contents.indexOf("*") < contents.indexOf("/") || contents.indexOf("/") == -1)) {
				contents = contents.replace("" + number1 + "*" + number2, "" + (totalIndecies++));
				operations.add(new FunctionOperation(FunctionOperation.MULTIPLY, parsedNum1, parsedNum2, totalIndecies - 1));
			} else {
				contents = contents.replace("" + number1 + "/" + number2, "" + (totalIndecies++));
				operations.add(new FunctionOperation(FunctionOperation.DIVIDE, parsedNum1, parsedNum2, totalIndecies - 1));

			}
		}
		while (contents.contains("+") || (contents.lastIndexOf("-") != 0 && (contents.split("-").length - (contents.charAt(0) == '-' ? 1 : 0)) > contents.split("E-").length)) {
			String[] unfilteredHalves = null;
			if (contents.indexOf("+") != -1 && (contents.indexOf("-") != -1)) { //Contains both

				if (contents.matches("[^+E]*[-].*[+].*&&[^-].*")) {
					unfilteredHalves = getFirstSubtractionSignAndBreak(contents);
				} else {
					unfilteredHalves = contents.split("[+]");
				}
			} else {
				if (contents.contains("+")) {
					unfilteredHalves = contents.split("[+]");
				} else {
					unfilteredHalves = getFirstSubtractionSignAndBreak(contents);
				}
			}
			try {
				String number1 = getNumberFromEnd(unfilteredHalves[0]);
				String number2 = getNumberFromBeginning(unfilteredHalves[1]);
				int parsedNum1 = Integer.parseInt(number1);
				int parsedNum2 = Integer.parseInt(number2);
				if (contents.indexOf("+") != -1 && (contents.indexOf("-") != -1)) { //Contains both
					if (contents.matches("[^+E]*[-].*[+].*&&[^-].*")) { // Does SUBTRACTION sign occur first
						contents = contents.replace("" + number1 + "-" + number2, "" + totalIndecies++);
						operations.add(new FunctionOperation(FunctionOperation.SUBTRACT, parsedNum1, parsedNum2, totalIndecies - 1));
					} else {
						contents = contents.replace("" + number1 + "+" + number2, "" + totalIndecies++);
						operations.add(new FunctionOperation(FunctionOperation.ADD, parsedNum1, parsedNum2, totalIndecies - 1));

					}
				} else { // Contains only one or the other.
					if (contents.contains("+")) {
						contents = contents.replace("" + number1 + "+" + number2, "" + totalIndecies++);
						operations.add(new FunctionOperation(FunctionOperation.ADD, parsedNum1, parsedNum2, totalIndecies - 1));
					} else {
						contents = contents.replace("" + number1 + "-" + number2, "" + totalIndecies++);
						operations.add(new FunctionOperation(FunctionOperation.SUBTRACT, parsedNum1, parsedNum2, totalIndecies - 1));
					}
				}
				//System.out.println(contents);
			} catch (Exception e) {
				System.out.println(contents + "|" + unfilteredHalves[0] + "|");
				throw e;
			}
		}
		while (contents.startsWith("-")) {
			String subContents = contents.substring(1, getNumberFromBeginning(contents).length());
			int d = createOrder(subContents);
			operations.add(new FunctionOperation(FunctionOperation.NEGATE, d, -1, d));
			contents = contents.replace("-" + subContents, "" + d);
		}
		try {
			System.out.println(contentsStart + ":" + contents);
			return Integer.parseInt(contents);
		} catch (Exception e) {
			System.out.println(contents);
			throw new RuntimeException();
		}
	}