   /// - parameter sender: Object that wants Espresso to quit
   @IBAction func terminate(_ sender: AnyObject) {
     // Terminate the caffeinate task, in case we're running any.
-    if let caffeinate = self.caffeinate {
-      caffeinate.terminate()
+    if caffeine.active {
+      caffeine.decaffeinate()
     }
-
     // Send the terminate message.
     NSApplication.shared().terminate(self)
   }

      // Define the target of the click actions.
      statusBtn.target = self
      // Define the left click action.
      statusBtn.action = #selector(AppController.toggleStatus(_:))
      // Set the status items button to appear disabled
      // (transculant appearance)
      statusBtn.appearsDisabled = true

      // Display the app menu.
      statusItem.popUpMenu(menu)
    }
    // Set highlighted to false when the application menu closes.
    sender.isHighlighted = false
  }

  /// Either terminates or launches a caffeinate task, depending
  /// on whether a task is already running.
  func toggleStatus() {
    if caffeine.active {
      caffeine.decaffeinate()
    } else {
      caffeine.caffeinate()
    }
  }

