       el
 
     @subscriptions.add atom.commands.add 'atom-text-editor',
-      'haskell-ghc-mod:type': ->
-        @getModel().haskellGhcModController?.getType()
-      'haskell-ghc-mod:info': ->
-        @getModel().haskellGhcModController?.getInfo()
-      'haskell-ghc-mod:insert-type': ->
-        @getModel().haskellGhcModController?.insertType()
-      'haskell-ghc-mod:check': ->
-        @getModel().haskellGhcModController?.doCheck()
+      'haskell-ghc-mod:type': ({target}) =>
+        @editorMap.get(target.getModel())?.getType()
+      'haskell-ghc-mod:info': ({target}) =>
+        @editorMap.get(target.getModel())?.getInfo()
+      'haskell-ghc-mod:insert-type': ({target}) =>
+        @editorMap.get(target.getModel())?.insertType()
+      'haskell-ghc-mod:check': ({target}) =>
+        @editorMap.get(target.getModel())?.doCheck()
 
     @subscriptions.add atom.workspace.observeTextEditors (editor) =>
       return unless editor.getGrammar().scopeName=="source.haskell"
       @numInstances += 1
       @process = new GhcModiProcess unless @process
-      editor.haskellGhcModController = new EditorController(@process,editor)
+      @editorMap.set(editor,new EditorController(@process,editor))
       editor.onDidDestroy =>
-        editor.haskellGhcModController?.destroy()
+        @editorMap.get(editor)?.destroy()
+        @editorMap.delete(editor)
         @numInstances -= 1
         if @numInstances==0
           @process?.destroy()


  deactivate: ->
    for editor in atom.workspace.getEditors()
      editor.haskellGhcModController?.destroy()
    @subscriptions.dispose()
    @process?.destroy()

    @subscriptions = new CompositeDisposable
    @process=null
    @numInstances=0
    @editorMap = new WeakMap

    atom.views.addViewProvider HaskellGhcModMessage, (message)->
      el=new HaskellGhcModMessageElement
