       'atom-latex:tools-backquote': () => @latex.provider.syntax.backquote()
       'atom-latex:tools-doublequote': () => @latex.provider.syntax.doublequote()
 
+    path = require 'path'
     @disposables.add atom.workspace.observeTextEditors (editor) =>
       @disposables.add editor.onDidSave () =>
         if atom.config.get('atom-latex.build_after_save') and \
             editor.buffer.file?.path and \
             path.extname(editor.buffer.file?.path) == '.tex'
-          @latex.builder.build()
+          @latex.builder.build
 
   deactivate: ->
-    return @disposables.dispose()
+    @latex?.dispose()
+    @disposables.dispose()
 
   provide: ->
     if !@provider?

            (grammar.scopeName.indexOf('text.tex.latex') > -1) or
            (grammar.name is 'LaTeX')
          promise = new Promise (resolve, reject) =>
            @lazyLoad()
            resolve()

  lazyLoad: ->
    @activated = true

    @latex = new AtomLaTeX

module.exports =
  config: require './config'

  activate: ->
    { CompositeDisposable } = require 'atom'
    @disposables = new CompositeDisposable
    @activated = false
    global.atom_latex = this
