             TermBase.run = ->
                 throw new Error("You should remove .run() from your queries when using the Data Explorer.\nThe query will be built and sent by the Data Explorer itself.")
 
+    # Open a connection to the server
     connect: (callback) ->
         r.connect @server, callback
 
+    # Run a query once
     run_once: (query, callback) =>
         @connect (error, connection) =>
             if error?

window.system_db = 'rethinkdb'

$ ->
    window.r = require('rethinkdb')
    window.driver = new Driver

    main_view = new MainView.MainContainer()
    $('body').html main_view.render().$el

    main_view.start_router()

    Backbone.sync = (method, model, success, error) ->

                                query.private_run connection, (err, result) =>
                                    if typeof result?.toArray is 'function'
                                        result.toArray (err, result) =>
                                            # This happens if people load the page with the back button
                                            # In which case, we just restart the query
                                            if err?.message is "This HTTP connection is not open"
                                                return @run query, delay, callback, index
                                            callback(err, result)
                                            if @timers[index]?
                                                @timers[index].timeout = setTimeout fn, delay
                                    else
                                        if err?.message is "This HTTP connection is not open"
                                            return @run query, delay, callback, index
                                        callback(err, result)
                                        if @timers[index]?
                                            @timers[index].timeout = setTimeout fn, delay
                            )()
        )(index)
        index

    # Stop the timer and close the connection
    stop_timer: (timer) =>
        clearTimeout @timers[timer].timeout
        @timers[timer].connection.close {noreplyWait: false}
