         sorted = if range.sort and range.sort.column
           direction = if range.sort.direction is 'asc' then 1 else -1
           column = range.sort.column
-          filtered.sort (r1, r2) -> direction * options.compare(r1.cells[column], r2.cells[column])
-          filtered
-        else filtered
+          filterCache.sort (r1, r2) -> direction * options.compare(r1.cells[column], r2.cells[column])
+          filterCache
+        else filterCache
         sortCacheTerm.column = range.sort?.column
         sortCacheTerm.direction = range.sort?.direction
 

    totalCount: (cb) -> cb(data.rows.length)
    rows: (range, cb) ->
      if range.sort?.column isnt sortCacheTerm.column
        filtered = undefined

      if range.useAdvancedSearch
        advancedSearchFilterFn = (row) -> options.advancedSearch(range.advancedSearch, row)
        filtered = getFiltered(data.rows, range.advancedSearch, filtered, filterCacheTerm, advancedSearchFilterFn)
        filterCacheTerm = range.advancedSearch
        sorted = undefined
      else
        filterFn = (row) -> options.filter(range.filter, row)
        filtered = getFiltered(data.rows, range.filter, filtered, filterCacheTerm, filterFn)
        filterCacheTerm = range.filter
        sorted = undefined


  options.advancedSearch ?= getAdvancedSearchFilter(options.cellValueLookup, options.termLookup)

  # cached values
  filterCache = undefined
  filterCacheTerm = undefined
  sorted = undefined
  sortCacheTerm = {}
