     version = atom.getVersion()
     args.push('--themes') if loadThemes
     args.push('--compatible', version) if semver.valid(version)
-
-    apmProcess = @runCommand args, (code, stdout, stderr) ->
-      if code is 0
-        try
-          packages = JSON.parse(stdout) ? []
-        catch parseError
-          error = createJsonParseError('Fetching featured packages failed.', parseError, stdout)
-          return callback(error)
-
-        callback(null, packages)
-      else
-        error = new Error('Fetching featured packages failed.')
-        error.stdout = stdout
-        error.stderr = stderr
-        callback(error)
-
-    handleProcessErrors(apmProcess, 'Fetching featured packages failed.', callback)
+    errorMessage = 'Fetching featured packages failed.'
+
+    apmProcess = @runCommand args, (code, stdout, stderr) ->
+      if code is 0
+        try
+          packages = JSON.parse(stdout) ? []
+        catch parseError
+          error = createJsonParseError(errorMessage, parseError, stdout)
+          return callback(error)
+
+        callback(null, packages)
+      else
+        error = new Error(errorMessage)
+        error.stdout = stdout
+        error.stderr = stderr
+        callback(error)
+
+    handleProcessErrors(apmProcess, errorMessage, callback)
 
   loadOutdated: (callback) ->
     args = ['outdated', '--json']
     version = atom.getVersion()
     args.push('--compatible', version) if semver.valid(version)
-
-    apmProcess = @runCommand args, (code, stdout, stderr) ->
-      if code is 0
-        try
-          packages = JSON.parse(stdout) ? []
-        catch parseError
-          error = createJsonParseError('Fetching outdated packages and themes failed.', parseError, stdout)
-          return callback(error)
-
-        callback(null, packages)
-      else
-        error = new Error('Fetching outdated packages and themes failed.')
-        error.stdout = stdout
-        error.stderr = stderr
-        callback(error)
-
-    handleProcessErrors(apmProcess, 'Fetching outdated packages and themes failed.', callback)
+    errorMessage = 'Fetching outdated packages and themes failed.'
+
+    apmProcess = @runCommand args, (code, stdout, stderr) ->
+      if code is 0
+        try
+          packages = JSON.parse(stdout) ? []
+        catch parseError
+          error = createJsonParseError(errorMessage, parseError, stdout)
+          return callback(error)
+
+        callback(null, packages)
+      else
+        error = new Error(errorMessage)
+        error.stdout = stdout
+        error.stderr = stderr
+        callback(error)
+
+    handleProcessErrors(apmProcess, errorMessage, callback)
 
   loadPackage: (packageName, callback) ->
     args = ['view', packageName, '--json']
-
-    apmProcess = @runCommand args, (code, stdout, stderr) ->
-      if code is 0
-        try
-          packages = JSON.parse(stdout) ? []
-        catch parseError
-          error = createJsonParseError("Fetching package '#{packageName}' failed.", parseError, stdout)
-          return callback(error)
-
-        callback(null, packages)
-      else
-        error = new Error("Fetching package '#{packageName}' failed.")
-        error.stdout = stdout
-        error.stderr = stderr
-        callback(error)
-
-    handleProcessErrors(apmProcess, "Fetching package '#{packageName}' failed.", callback)
+    errorMessage = "Fetching package '#{packageName}' failed."
+
+    apmProcess = @runCommand args, (code, stdout, stderr) ->
+      if code is 0
+        try
+          packages = JSON.parse(stdout) ? []
+        catch parseError
+          error = createJsonParseError(errorMessage, parseError, stdout)
+          return callback(error)
+
+        callback(null, packages)
+      else
+        error = new Error(errorMessage)
+        error.stdout = stdout
+        error.stderr = stderr
+        callback(error)
+
+    handleProcessErrors(apmProcess, errorMessage, callback)
 
   loadCompatiblePackageVersion: (packageName, callback) ->
     args = ['view', packageName, '--json', '--compatible', @normalizeVersion(atom.getVersion())]
-
-    apmProcess = @runCommand args, (code, stdout, stderr) ->
-      if code is 0
-        try
-          packages = JSON.parse(stdout) ? []
-        catch parseError
-          error = createJsonParseError("Fetching package '#{packageName}' failed.", parseError, stdout)
-          return callback(error)
-
-        callback(null, packages)
-      else
-        error = new Error("Fetching package '#{packageName}' failed.")
-        error.stdout = stdout
-        error.stderr = stderr
-        callback(error)
-
-    handleProcessErrors(apmProcess, "Fetching package '#{packageName}' failed.", callback)
+    errorMessage = "Fetching package '#{packageName}' failed."
+
+    apmProcess = @runCommand args, (code, stdout, stderr) ->
+      if code is 0
+        try
+          packages = JSON.parse(stdout) ? []
+        catch parseError
+          error = createJsonParseError(errorMessage, parseError, stdout)
+          return callback(error)
+
+        callback(null, packages)
+      else
+        error = new Error(errorMessage)
+        error.stdout = stdout
+        error.stderr = stderr
+        callback(error)
+
+    handleProcessErrors(apmProcess, errorMessage, callback)
 
   getInstalled: ->
     Q.nbind(@loadInstalled, this)()


  loadInstalled: (callback) ->
    args = ['ls', '--json']
    apmProcess = @runCommand args, (code, stdout, stderr) ->
      if code is 0
        try
          packages = JSON.parse(stdout)
        catch parseError
          error = createJsonParseError('Fetching local packages failed.', parseError, stdout)
          return callback(error)
        callback(null, packages)
      else
        error = new Error('Fetching local packages failed.')
        error.stdout = stdout
        error.stderr = stderr
        callback(error)

    handleProcessErrors(apmProcess, 'Fetching local packages failed.', callback)

  loadFeatured: (loadThemes, callback) ->
    unless callback


    atom.packages.deactivatePackage(name) if atom.packages.isPackageActive(name)

    errorMessage = "Uninstalling \u201C#{name}\u201D failed."
    onError = (error) =>
      @emitPackageEvent 'uninstall-failed', pack, error
      callback(error)
