       // Display the app menu.
       statusItem.popUpMenu(menu)
     }
-    // Disable the highlighting of the status bar item when
-    // the app menu closes.
+    // 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.
-  ///
-  /// - parameter sender: Status bar button that sends the action.
-  func toggleStatus(_ sender: NSStatusBarButton?) {
-    guard let sender = sender else {
-      return
-    }
-    // Check wether a caffeinate task is already
-    // running or not
-    if caffeinate.isRunning() {
-      // Terminate the running caffeinate task.
-      caffeinate.terminate()
-      // Let the menu bar icon appear disabled.
-      sender.appearsDisabled = true
+  func toggleStatus() {
+    if caffeine.active {
+      caffeine.decaffeinate()
     } else {
-      // Launch a new caffeinate task.
-      caffeinate.launch()
-      // Let the menu bar icon appea enabled.
-      sender.appearsDisabled = false
+      caffeine.caffeinate()
     }
   }
 

  /// Holds the status bar item.
  var statusItem: NSStatusItem!
  /// Manages the caffeinate task.
  var caffeinate: CaffeinateController!

  /// Holds the menu item.
  @IBOutlet weak var menu: NSMenu!

  /// Menu item to launch Espresso at login
  @IBOutlet weak var launchAtLogin: NSMenuItem!
  /// Menu item to activate Espresso at launch
  @IBOutlet weak var activateOnLaunch: NSMenuItem!


  override init() {
    // Make sure everything is set up properly before
    // initializing the class specific properties.
    super.init()

    // Configure the status bar item.
    configureStatusItem()
    // Init the caffeinate controller.
    caffeinate = CaffeinateController()
  }

  /// Do some setup work when launching the app.
  override func awakeFromNib() {
    // Init the PreferenceManager to get the user defaults.
    let prefs = PreferenceManager()
    if prefs.activateOnLaunch {
      toggleStatus(nil)
    }
  }


      // 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
