     _init: (args) ->
       @config = @_updateConfig args
       @el = document.getElementById @config.id
+      @xhr = @_setupXHR()
       @_addEventHandlers()
       @results = @_buildResults()
-      @xhr = @_setupXHR()
 
     _updateConfig: (args) ->
       newConfig = {}

      @_addClass results, @config.resultsClass
      @_addClass results, "#{@config.resultsClass}--#{@config.classModifier}" if @config.classModifier

      results.addEventListener 'click', (e) =>
        @_resultsClick e
      , false

      results.addEventListener 'mouseover', (e) =>
        @_resultsMouseOver e.target
      , false

      results.addEventListener 'mouseout', (e) =>
        @_resultsMouseOut e.target
      , false

      results

    # event handlers

      newConfig[key] = value for own key, value of args
      newConfig

    _on: (elt, evt, callback) ->
      if window.addEventListener
        elt.addEventListener evt, callback, false
      else if window.attachEvent
        elt.attachEvent "on#{evt}", callback

    _addEventHandlers: ->
      @_on(@el, 'input', (e) =>
        @_searchFor e.currentTarget.value
      )
      @_on(@el, 'keydown', (e) =>
        @_keypressHandler e
      )

    _setupXHR: ->
      xhr = new XMLHttpRequest()
      xhr.onreadystatechange = =>
        if @xhr.readyState == 4
          if @xhr.status == 200
            @_populateResults JSON.parse(@xhr.responseText), @currentSearch
