anchor.diff:    Parser(): lex = new Lexer();
   
     /**
  -   * Parses the given input string into an [Expression]. Throws a [StateError]
  -   * if the token stream is invalid. Returns a valid [Expression].
  +   * Parses the given input string into an [Expression]. Throws a [ArgumentError]
  +   * if the given [inputString] is empty. Throws a [StateError]if the token stream
  +   * is invalid. Returns a valid [Expression].
      */
     Expression parse(String inputString) {
  -    List<Expression> expressionStack = new List<Expression>();
  +    if (inputString == null || inputString.trim().isEmpty) {
  +      throw new ArgumentError("The given input string was empty.");
  +    }
  +    
  +    List<Expression> exprStack = new List<Expression>();
       List<Token> inputStream = lex.tokenizeToRPN(inputString);
   
  -    for (var i = 0; i < inputStream.length; i++){
  -      Token currentToken = inputStream[i];
  -      Expression currentExpression;
  -
  -      if(currentToken.type == TokenType.VAL) {
  -        currentExpression = new Number(double.parse(currentToken.text));
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.VAR) {
  -        Expression currentExpression = new Variable(currentToken.text);
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.PLUS) {
  -        Expression rightOperand = expressionStack.removeLast();
  -        Expression leftOperand = expressionStack.removeLast();
  -        currentExpression = leftOperand + rightOperand;
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.MINUS) {
  -        Expression rightOperand = expressionStack.removeLast();
  -        Expression leftOperand = expressionStack.removeLast();
  -        currentExpression = leftOperand - rightOperand;
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.TIMES) {
  -        Expression rightOperand = expressionStack.removeLast();
  -        Expression leftOperand = expressionStack.removeLast();
  -        currentExpression = leftOperand * rightOperand;
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.DIV) {
  -        Expression rightOperand = expressionStack.removeLast();
  -        Expression leftOperand = expressionStack.removeLast();
  -        currentExpression = leftOperand / rightOperand;
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.POW) {
  -        Expression rightOperand = expressionStack.removeLast();
  -        Expression leftOperand = expressionStack.removeLast();
  -        currentExpression = leftOperand ^ rightOperand;
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.UNMINUS) {
  -        Expression operand = expressionStack.removeLast();
  -        currentExpression = - operand;
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.LOG) {
  -        Expression rightOperand = expressionStack.removeLast();
  -        Expression leftOperand = expressionStack.removeLast();
  -        currentExpression = new Log(leftOperand, rightOperand);
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.LN) {
  -        Expression operand = expressionStack.removeLast();
  -        currentExpression = new Ln(operand);
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -
  -      if(currentToken.type == TokenType.SQRT) {
  -        Expression operand = expressionStack.removeLast();
  -        currentExpression = new Sqrt(operand);
  -        expressionStack.add(currentExpression);
  -        continue;
  +    for (Token currToken in inputStream){
  +      Expression currExpr, left, right;
  +
  +      switch(currToken.type) {
  +        case TokenType.VAL: 
  +          currExpr = new Number(double.parse(currToken.text));
  +          break;
  +        case TokenType.VAR:
  +          currExpr = new Variable(currToken.text);
  +          break;
  +        case TokenType.UNMINUS:
  +          currExpr = -exprStack.removeLast();
  +          break;
  +        case TokenType.PLUS:
  +          right = exprStack.removeLast();
  +          left = exprStack.removeLast();
  +          currExpr = left + right;
  +          break;
  +        case TokenType.MINUS:
  +          right = exprStack.removeLast();
  +          left = exprStack.removeLast();
  +          currExpr = left - right;
  +          break;
  +        case TokenType.TIMES:
  +          right = exprStack.removeLast();
  +          left = exprStack.removeLast();
  +          currExpr = left * right;
  +          break;
  +        case TokenType.DIV:
  +          right = exprStack.removeLast();
  +          left = exprStack.removeLast();
  +          currExpr = left / right;
  +          break;
  +        case TokenType.POW:
  +          right = exprStack.removeLast();
  +          left = exprStack.removeLast();
  +          currExpr = left ^ right;
  +          break;
  +        case TokenType.EFUNC:
  +          currExpr = new Exponential(exprStack.removeLast());
  +          break;
  +        case TokenType.LOG:
  +          right = exprStack.removeLast();
  +          left = exprStack.removeLast();
  +          currExpr = new Log(left, right);
  +          break;
  +        case TokenType.LN:
  +          currExpr = new Ln(exprStack.removeLast());
  +          break;
  +        case TokenType.SQRT:
  +          currExpr = new Sqrt(exprStack.removeLast());
  +          break;
  +        case TokenType.ROOT:
  +          right = exprStack.removeLast();
  +          left = exprStack.removeLast();
  +          currExpr = new Root.fromExpr((left as Number), right);
  +          break;
  +        case TokenType.SIN:
  +          currExpr = new Sin(exprStack.removeLast());
  +          break;
  +        case TokenType.COS:
  +          currExpr = new Cos(exprStack.removeLast());
  +          break;
  +        case TokenType.TAN:
  +          currExpr = new Tan(exprStack.removeLast());
  +          break;
  +        default: throw new ArgumentError('Unsupported token: $currToken');
         }
         
  -      if(currentToken.type == TokenType.COS) {
  -        Expression operand = expressionStack.removeLast();
  -        currentExpression = new Cos(operand);
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -      
  -      if(currentToken.type == TokenType.SIN) {
  -        Expression operand = expressionStack.removeLast();
  -        currentExpression = new Sin(operand);
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -      
  -      if(currentToken.type == TokenType.EFUNC) {
  -        Expression operand = expressionStack.removeLast();
  -        currentExpression = new Exponential(operand);
  -        expressionStack.add(currentExpression);
  -        continue;
  -      }
  -    }
  -
  -    if(expressionStack.length > 1){
  +      exprStack.add(currExpr);
  +    }
  +
  +    if(exprStack.length > 1) {
         throw new StateError("The input String is not a correct expression");
       }
   
  -    return expressionStack.last;
  +    return exprStack.last;
     }
   }
   
  
positive.code:     keywords["*"] = TokenType.TIMES;
      keywords["/"] = TokenType.DIV;
      keywords["^"] = TokenType.POW;
      keywords["rt"] = TokenType.ROOT;
      keywords["sqrt"] = TokenType.SQRT;
      keywords["log"] = TokenType.LOG;
      keywords["cos"] = TokenType.COS;
  
negative.code:     if(stream.isEmpty) {
        throw new ArgumentError("The given tokenStream was empty.");
      }
      
      List<Token> outputStream = new List<Token>();
      List<Token> operatorBuffer = new List<Token>();
  
      for(Token curToken in stream) {
        // If the current Token is a value or a variable, put them into the output stream.
        if(curToken.type == TokenType.VAL || curToken.type == TokenType.VAR) {
          outputStream.add(curToken);
          continue;
        }
        
        // If the current Token is a function, put it onto the operator stack.
        if(curToken.type.function) {
          operatorBuffer.add(curToken);
          continue;
        }
        
        /*
         *  If the current Token is a function argument separator, pop operators
         *  to output stream until a left brace is encountered.
         */
        if(curToken.type == TokenType.SEPAR) {
          while(!operatorBuffer.isEmpty && operatorBuffer.last.type != TokenType.LBRACE) {
            outputStream.add(operatorBuffer.removeLast());
          }
          // If no left brace is encountered, separator was misplaced or parenthesis mismatch
          if(!operatorBuffer.isEmpty && operatorBuffer.last.type != TokenType.LBRACE) {
            //TODO never reached, check this.
            throw new StateError('Misplaced separator or mismatched parenthesis.');
          }
          continue;
        }
       
        /*
         * Special case for unary minus: If the current token type is MINUS and the last
         * token is of type LBRACE, the current token is considered an unary minus.
         * 
         * This allows unary minus in parenthesis to be parsed correctly.
         * 
         * TODO: This is buggy, find a better solution for unary minus.
         */
        /*
        if( curToken.type.operator && curToken.type == TokenType.MINUS &&
            !operatorBuffer.isEmpty && operatorBuffer.last.type == TokenType.LBRACE) {
          operatorBuffer.add(new Token(curToken.text, TokenType.UNMINUS));
        }
        */
        
        /* 
         * If the current token is an operator and it's priority is lower than the priority of the last
  