         @process(@source)
 
   process: (results) ->
-    that = this
-    if results.length and typeof results[0] != "string"
-      @strings = false
+    @strings = false if results.length and typeof results[0] isnt "string"
     @query = @$element.val()
-    if !@query
-      if @shown then @hide() else this
-
-    items = $.grep results, (item) ->
-      if !that.strings
-        item = item[that.options.property]
-      if that.matcher(item)
-        return item
-
-    # items = @sorter(items)
-    if !items.length and !@allowNew
-      return if @shown then @hide() else @
-
+    return @hide() if !@query and typeof @source is "function"
+    items = @sorter $.grep results, (item) =>
+      item = item[@options.property] unless @strings
+      item if @matcher(item)
+    return @hide() if !items.length and !@options.otherOption
     @render(items.slice(0, @options.items)).show()
 
   matcher: (item) ->

    @move(e)

  keyup: (e) ->

    switch e.keyCode
      when 40, 38 # down / up arrow
        break
      when 9 # tab
        return if !@shown
        @select()
      when 13 # enter
        if !@shown
          @onenter(e) if typeof @onenter == "function"
          @select() if @allowNew
        else
          @select()
        break
      when 27 # escape
        return if !@shown
        @hide()
        break
      else
        @lookup()

    e.stopPropagation()
    e.preventDefault()

  focus: (e) ->
    @focused = true

  blur: (e) ->
    @focused = false
    that = @
    e.stopPropagation()
    e.preventDefault()
    setTimeout ->
      that.hide()
    , 150

  click: (e) ->
    e.stopPropagation()
    e.preventDefault()
    @select(true)
    @$element.focus()

  mouseenter: (e) ->
    @mousedover = true

    beginswith = []
    caseSensitive = []
    caseInsensitive = []
    item = undefined
    sortby = undefined
    while item = items.shift()
      if @strings
        sortby = item
      else
        sortby = item[@options.property]
      unless sortby.toLowerCase().indexOf(@query.toLowerCase())
        beginswith.push item
      else if ~sortby.indexOf(@query)
        caseSensitive.push item
      else
        caseInsensitive.push item
    beginswith.concat caseSensitive, caseInsensitive

  highlighter: (item) ->
    item.replace new RegExp('(' + @query + ')', 'ig'), ($1, match) ->
