       initialize: (opts={})->
         super
         @val = opts.value
-
-      doAppend: (expression)->
-        last = expression.last()
-        number_with_this_val = @comps.build_number(value: @val)
-
-        if last && last instanceof @comps.classes.number
-          new_last = last.concatenate(@val)
-          expression.replaceLast(new_last)
-        else if (last && last instanceof @comps.classes.exponentiation) or (last && !last.isOperator())
-          expression.append(@comps.build_multiplication()).
-            append(number_with_this_val)
-        else
-          expression.append(number_with_this_val)
-
-      invoke: (expression)->
-        _FinalOpenSubExpressionApplication.build(expr: expression, comps: @comps).
-          invokeOrDefault((expr)=> @doAppend(expr))
+      # doAppend: (expression)->
+      #   last = expression.last()
+      #   number_to_append = @comps.build_number(value: @val)
+
+      #   if last && last instanceof @comps.classes.number
+      #     new_last = last.concatenate(@val)
+      #     new_exp = expression.replaceLast(new_last)
+      #   else if (last && last instanceof @comps.classes.exponentiation) or (last && !last.isOperator())
+      #     new_exp = expression.append(@comps.build_multiplication()).
+      #       append(number_to_append)
+      #   else
+      #     new_exp = expression.append(number_to_append)
+
+      #   @pointer = @pos.build(position: new_exp.id())
+      #   new_exp
+
+      # @destructive
+      doAppendD: (expression, expression_position)->
+        number_to_append = @comps.build_number(value: @val)
+        last = expression.last()
+        if last
+          if last instanceof @comps.classes.number
+            expression.last().concatenateD(@val)
+          else if (last instanceof @comps.classes.exponentiation) or !last.isOperator()
+            expression.appendD(@comps.build_multiplication())
+            expression.appendD(number_to_append)
+          else
+            expression.appendD(number_to_append)
+        else
+          expression.appendD(number_to_append)
+
+      perform: (expression_position)->
+        result_exp = _ExpressionManipulator.build(expression_position.expression()).clone().
+          withComponent(expression_position, (component)=>
+            @doAppendD(component, expression_position)
+          ).value()
+
+        # would be same position, but a new expression
+        expression_position.clone(expression: result_exp)
 
     class_mixer(AppendNumber)
 

        else
          power.open()

      invoke: (expression)->
        last = expression.last()

        # in the first case, our base case comes


    class_mixer(Negation)

    class AppendOpenSubExpression extends ExpressionManipulation
      action: (expression)->
        new_exp = @comps.build_expression().open()
        @pointer = @pos.build(position: new_exp.id())
        _ImplicitMultiplication.build(@comps).
          invoke(expression).
          append(new_exp)

      perform: (expression)->
        exp = _FinalOpenSubExpressionApplication.build(expr: expression, comps: @comps).
          performOrDefault((expression)=> @action(expression))
        expression: exp
        position: @pointer


    class_mixer(AppendOpenSubExpression)

    class CloseSubExpression extends ExpressionManipulation
      perform: (expression)->
        ret = _FinalOpenSubExpressionApplication.build(expr: expression, comps: @comps).
          perform((expression)-> expression.close())
        ret
    class_mixer(CloseSubExpression)

    # TODO this needs to ahve final open sub expression application
    class AppendPi extends ExpressionManipulation
      perform: (expression)->
        _ImplicitMultiplication.build(@comps).
          invoke(expression).
          append(@comps.build_pi())

    class_mixer(AppendPi)

    class AppendRoot extends ExpressionManipulation
      initialize: (opts={})->
        super
        @degree = opts.degree

      perform: (expression_position)->
        degree =
          if @degree
            @comps.build_expression expression: [
              @comps.build_number(value: @degree)
            ]
          else
            @comps.build_expression()
        radicand = @comps.build_expression(expression: [])
        root = @comps.build_root(degree: degree, radicand: radicand)

        result_exp = _ExpressionManipulator.build(expression_position.expression()).clone().
          withComponent(expression_position, (component)=>
            _ImplicitMultiplication.build(@comps).invokeD(component)
            component.appendD(root)
          ).value()

        # would be same position, but a new expression
        expression_position.clone(expression: result_exp)

    class_mixer(AppendRoot)

    class AppendVariable extends ExpressionManipulation
      initialize: (opts={})->
        super
        @variable_name = opts.variable
      perform: (expression)->
        variable = @comps.build_variable(name: @variable_name)
        _ImplicitMultiplication.build(@comps).
          invoke(expression).
          append(variable)


    class_mixer(AppendVariable)

    class SquareRoot extends ExpressionManipulation
      perform: (expression)->
        value = @value(expression)
        root = Math.sqrt(parseFloat(value))
        unless isNaN(root)
          num = @comps.build_number value: "#{root}"
          @comps.classes.expression.buildWithContent [num]
        else
          @comps.classes.expression.buildError()
    class_mixer(SquareRoot)


    class Reset extends ExpressionManipulation
      perform:  (expression, position)->
        empty_expression = @comps.build_expression(expression: [])
        @pos.build(expression: empty_expression, position: empty_expression.id())
    class_mixer(Reset)

    class UpdatePosition extends ExpressionManipulation
      initialize: (opts={})->
        super
        @new_position_element_id = opts.element_id
        @new_position_element_type = opts.type

      perform:  (expression_position)->
        expression_position.clone(position: @new_position_element_id, type: @new_position_element_type)

    class_mixer(UpdatePosition)


    class _FinalOpenSubExpressionApplication
      initialize: (opts={})->
