     serialize: ->
         atomTodoistViewState: @atomTodoistView.serialize()
 
-    toggle: ->
-        if @rightPanel.isVisible()
-            @rightPanel.hide()
+    toggle: (state)->
+        if @toggled
+          @toggled = false
+          @rightPanel.destroy()
+          @atomTodoistView.destroy()
         else
-            @rightPanel.show()
+          @toggled = true
+          @atomTodoistView = new AtomTodoistView(state.atomTodoistViewState)
+          @rightPanel = atom.workspace.addRightPanel(item: @atomTodoistView.getElement(), visible: false)
+          @rightPanel.show()

    activate: (state) ->
        @atomTodoistView = new AtomTodoistView(state.atomTodoistViewState)
        @rightPanel = atom.workspace.addRightPanel(item: @atomTodoistView.getElement(), visible: false)

        # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
        @subscriptions = new CompositeDisposable

        # Register command that toggles this view
        @subscriptions.add atom.commands.add 'atom-workspace', 'atom-todoist:toggle': => @toggle()

    deactivate: ->
        @rightPanel.destroy()

    atomTodoistView: null
    rightPanel: null
    subscriptions: null
    toggled: false
    config:
        token:
            type: 'string'
