             console.error('This type is not sortable', typeCode)
             return
 
-        compare = resultsView.compare
-
-        resultset.rows.sort (left, right) ->
-            return compare(typeCode, left[columnIndex], right[columnIndex], ascending)
+        resultset.rows.sort (left, right) =>
+            return @compare(typeCode, left[columnIndex], right[columnIndex], ascending)
 
     createTh: (text, resultsetIndex, columnIndex) ->
-        resultsView = @
         th = document.createElement('th')
         th.textContent = text
         th.setAttribute('column_index', columnIndex)
         th.setAttribute('resultset_index', resultsetIndex)
-        if resultsView.canTypeBeSorted(resultsView.resultsets[resultsetIndex].columns[columnIndex].type_code)
+        if @canTypeBeSorted(@resultsets[resultsetIndex].columns[columnIndex].type_code)
             th.classList.add('sortable')
-            if resultsView.resultsets[resultsetIndex].columns[columnIndex].ascending == true
+            if @resultsets[resultsetIndex].columns[columnIndex].ascending == true
                 th.textContent = th.textContent + ' +'
-            else if resultsView.resultsets[resultsetIndex].columns[columnIndex].ascending == false
+            else if @resultsets[resultsetIndex].columns[columnIndex].ascending == false
                 th.textContent = th.textContent + ' -'
 
-        th.onclick = ->
-            resultsView.sort(resultsView.resultsets[this.getAttribute('resultset_index')], this.getAttribute('column_index'), true, resultsView)
-            resultsView.update(resultsView.resultsets)
+        th.onclick = =>
+            @sort(@resultsets[this.getAttribute('resultset_index')], this.getAttribute('column_index'), true)
+            @update(@resultsets)
         return th
 
     createTable: (x, resultsetIndex) ->

        clear = toolbar.appendChild(document.createElement('div'))
        clear.classList.add('clear')

        i = 0
        for resultset in resultsets
            @element.appendChild(@createTable(resultset, i))
            i++

    destroy: ->
        @element.remove()

    resultsets: []

    canTypeBeSorted: (typeCode) ->
        return Type[typeCode]?

    compare: (typeCode, left, right, asc) ->
        return Type[typeCode]?.compare(left, right) * if asc then 1 else -1 ? 0

    sort: (resultset, columnIndex, asc) ->
        if resultset.columns[columnIndex].ascending?
            resultset.columns[columnIndex].ascending = !resultset.columns[columnIndex].ascending
        else
