 
   unlink: (provider) ->
 
-    @loaders[provider].show()
+    { loader, toggle, scope, token, title } = @getDetails provider
+
+    loader.show()
 
     me = whoami()
     unlink = => me.unlinkOauth provider, (err) =>
       if err
-        @switches[provider].setOn no
-        @loaders[provider].hide()
+        toggle.setOn no
+        loader.hide()
         return showError err
 
       new kd.NotificationView
-        title: "Your #{@providers[provider]} integration is now disabled."
+        title: "Your #{title} integration is now disabled."
 
       @linked[provider] = no
-      @scopes[provider].unsetTooltip()
-      @scopes[provider].hide()
-
-      @tokens[provider].updatePartial "#{@providers[provider]} Integration"
-
-      @loaders[provider].hide()
+      scope.unsetTooltip()
+      scope.hide()
+
+      token.updatePartial "#{title} Integration"
+
+      loader.hide()
 
     if provider is 'github' and isAdmin()
 
       group = getGroup()
-      group.fetchDataAt ORG_TOKEN, (err, token) =>
-        return unlink()  if err or not token
-
-        if token is @linkedData.github.token
+      group.fetchDataAt ORG_TOKEN, (err, existingToken) =>
+        return unlink()  if err or not existingToken
+
+        if existingToken is @linkedData.github.token
 
           cc = kd.singletons.computeController
-          cc.ui.askFor 'disableTeamOAuth', {}, (status) =>
+          cc.ui.askFor 'disableTeamOAuth', {}, (status) ->
 
             if status.confirmed
               data = {}


  link: (provider) ->

    @loaders[provider].show()

    options  = { provider }
    redirect = =>
      kd.singletons.oauthController.redirectToOauthUrl options
      new kd.NotificationView
        title    : "Redirecting to #{@providers[provider]}..."
        duration : 0

    if provider is 'github' and isAdmin()
      group = getGroup()
      group.fetchDataAt ORG_TOKEN, (err, token) =>
        return redirect()  if err or token

        scope = TEAM_SCOPE
        cc = kd.singletons.computeController
        cc.ui.askFor 'enableTeamOAuth', { scope }, (status) =>
          if status.cancelled
            @switches[provider].setOff no
            @loaders[provider].hide()
          else
            options.scope = scope  if status.confirmed
            redirect()


      @supportedProviders.forEach (provider) =>

        { loader, toggle, scope, token, title } = @getDetails provider

        @linked[provider] = foreignAuth?[provider]?
        toggle.setDefaultValue @linked[provider]
        toggle.makeEnabled()
        loader.hide()

        @linkedData[provider] = foreignAuth?[provider] ? {}

        if @linked[provider] and existingScope = foreignAuth[provider].scope
          existingScope = existingScope.replace /,/g, ', '
          scope.updatePartial existingScope
          scope.setTooltip
            title: "Scopes: #{existingScope}"
          scope.show()
          token.updatePartial "
            #{title} Integration
            <cite>COPY TOKEN</cite>
            <token>#{@linkedData[provider].token}</token>
          "
        else
          scope.unsetTooltip()
          scope.hide()
          token.updatePartial "#{title} Integration"

      do callback

