                         else
                             complete.push(true)
                 if queryStillExecuting
-                    pgHoff.keepGoing(result.url, complete, pgHoff)
+                    @keepGoing(result.url, complete)
 
-                pgHoff.renderResults(result.resultsets, pgHoff)
-            .catch (err) ->
+                @renderResults(result.resultsets)
+            .catch (err) =>
                 atom.workspace.getActivePaneItem().alias = null
-                pgHoff.resultsViewPanel.hide()
+                @resultsViewPanel.hide()
                 atom.notifications.addError(err)


        pgHoff = @
        return @listServersView.connect(@listServersViewPanel)
            .then (server) ->
                if server.already_connected
                    atom.notifications.addInfo('Using ' + server.alias)
                else
                    atom.notifications.addSuccess('Connected to ' + server.alias)

                paneItem.alias = server.alias
            .catch (error) ->
                atom.notifications.addError(error)
            .finally ->
                pgHoff.listServersViewPanel.hide()

    renderResults: (resultsets, pgHoff) ->
        pgHoff.resultsViewPanel.show();
        pgHoff.resultsView.update(resultsets)

    keepGoing: (url, complete, pgHoff) ->
        interval = setInterval( () ->
            return PgHoffServerRequest.Get(url, false)
                .then (resultsets) ->
                    i = 0
                    for resultset in resultsets
                        if resultset.error
                            complete[i] = true
                            atom.notifications.addError(resultset.error)

                            else
                                if complete[i] == false
                                    complete[i] = true

                    @renderResults(resultsets, pgHoff)
                    if !complete.some( (val) -> return val == false )
                        clearInterval(interval)

                .catch (err) =>
                    console.error 'catch', err
                    clearInterval(interval)
                    atom.notifications.addError(err)
        , atom.config.get('pg-hoff.pollInterval'))

    executeQueryWithConnect: ->
        if atom.workspace.getActivePaneItem().alias?
            @executeQuery()
        else
            return @connect()?.then =>
                    @executeQuery()
                .catch (err) ->
                    console.error 'Connect error', err
                    atom.notifications.addError('Connect error')

    executeQuery: ->
        selectedText = atom.workspace.getActiveTextEditor().getSelectedText().trim()
        pgHoff = @
