     if @options.onChange
       @options.onChange equation, (results) =>
         if results.valid
-          @element.removeClass "maybevalid"
-          @element.removeClass "invalid"
-          @element.addClass "valid"
-          @errorMsg.hide()
+          @showSuccess()
         else
-          @element.removeClass "maybevalid"
-          @element.removeClass "valid"
-          @element.addClass "invalid"
-          @errorMsg.show()
+          @showError()
 
   isArrow: (code) ->
     $.inArray(code, [37, 38, 39, 40]) != -1
-
-  stripNbsp: (string) ->
-    string.replace(/&nbsp;/g, ' ')
 
   getRange: ->
     # Return currently selected range.

      @element.addClass "noborder"
      return

    @input = @element.find(".token-text-area-input")

    @input.attr "contenteditable", "true"
    @input.find(".token").attr("contenteditable", "false")

    @element.after('<div style="color: #b94a48; padding-left: 80px; margin-top: 10px; font-size: 12px; line-height: 16px;">Syntax error in formula.</div>')
    @errorMsg = @element.next()
    @errorMsg.hide()

    @typingTimer = null
    @resultMenu = null
    @resultList = null
    @word = null
    @range = null

    @createResultMenu()

    @registerEvents()

  registerEvents: ->

      html.empty().append(newContents)

    html.text().substr(0, caretPos)

  stripNbsp: (string) ->
    string.replace(/&nbsp;/g, '')

  fixWhitespace: ->
    html = @stripNbsp(@input.html())
    html = html.replace(/&nbsp;/g, ' ')
    html = html.replace(/[\s]+/g, ' ')
    @input.html(html)

  showSuccess: ->
    @element.removeClass "invalid"
    @element.removeClass "maybevalid"
    @element.addClass "valid"
    @msg.html(@SUCCESS_MSG)
    @msg.css('color', @SUCCESS_COLOR)

  showError: ->
    @element.removeClass "valid"
    @element.removeClass "maybevalid"
    @element.addClass "invalid"
    @msg.html(@ERROR_MSG)
    @msg.css('color', @ERROR_COLOR)

  showChecking: ->
    @element.removeClass "valid"
    @element.removeClass "invalid"
    @element.addClass "maybevalid"
    @msg.html(@CHECKING_MSG)
    @msg.css('color', @NEUTRAL_COLOR)
      
$.fn.tokenTextArea = (options, args...) ->
  @each ->
