 
       else if delta.retain?
         retain = parseInt delta.retain
-        from = @val position
-        to = @val (position + retain)
+        from = val position
+        to = val (position + retain)
 
         operation.call selections, from, to, delta.attributes
         return position + retain
 
-  insertHelper = (position, content) ->
+  insertHelper: (position, content) ->
     pusher = (position, char) =>
       if @_model?
         (@_get "characters").insert position, char


      if delta.insert?
        @insertHelper position, delta.insert
        from = @val position
        to = @val (position + delta.insert.length)
        operation.call selections, from, to, delta.attributes
        return position + delta.insert.length


        charObj = @createChar char
        pusher (position + offset), charObj

  deleteHelper: (position, length = 1) ->
    (@_get "characters").delete position, length

  createChar: (char, left=[], right=[]) ->
    return new Y.Object {
      char: char
      left: left
      right: right
    }

  # return the index of a character
  # @param character [Y.Object] the character to look for
  #TODO: check that it works
  indexOf: (character) ->
    (@_get "characters").val().indexOf(character)

  # pass deltas to the character instance
