diff --git a/client/catalog-dev/config-example.json b/client/catalog-dev/config-example.json
index 9c37d97..18c782e 100644
--- a/client/catalog-dev/config-example.json
+++ b/client/catalog-dev/config-example.json
@@ -1,18 +1,18 @@
 {
-	"global": {
-		"catalogPrefix": "/catalog",
-		"faceConfig": {
-			"host": "atmos-nwsc.ucar.edu",
-			"port": 9696
-		}
-	},
-	"retrieval": {
-		"demoKey": {
-			"pub": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAmnWYKE7E8G+hyy4TiTU7t91KyIGvglEeT6HWEkW4LKzXLO22a1jVS9+yP96I6vp7N5vpS1t7oXtgWuzkO+O85u6gfbvwp+67zJe2I89eHO4dmNnP4fx/j7WcCUCyzZfbyW67h5IoouoBIdQge2Xdvh9rFdex9UUhyjEZv5676zlcqlhz8xGBrJmQHsqpD9ijY1XhKBvoSIoQ0ZKkpmwVk8QYM9PbjUqzSQBj4aYXS+BPV6aRudVvyDt2DBXp2FNP0CGrosCXKnSl4Yv8BYp0k0RmFZDuJuntLb/XIvPEfMX5li7g3zHzAlIJIVSwT+FRkd3H5cECFSIZFUYIuSQQIDAQAB",
-			"priv": "MIIEpQIBAAKCAQEAuAmnWYKE7E8G+hyy4TiTU7t91KyIGvglEeT6HWEkW4LKzXLO22a1jVS9+yP96I6vp7N5vpS1t7oXtgWuzkO+O85u6gfbvwp+67zJe2I89eHO4dmNnP4fx/j7WcCUCyzZfbyW67h5IoouoBIdQge2Xdvh9rFdex9UUhyjEZv5676zlcqlhz8xGBrJmQHsqpD9ijY1XhKBvoSIoQ0ZKkpmwVk8QYM9PbjUqzSQBj4aYXS+BPV6aRudVvyDt2DBXp2FNP0CGrosCXKnSl4Yv8BYp0k0RmFZDuJuntLb/XIvPEfMX5li7g3zHzAlIJIVSwT+FRkd3H5cECFSIZFUYIuSQQIDAQABAoIBAQCKBftzfxavn6lM5T8m+GZN0vzRBsBg8Z/jpsYKSLOayiHNKYCIPaSFpXuCIYEo6/JDJLB2xVLvwupLgkGSwm2mrvCyJkihI38Cz6iQF6I+iia9bYrupgwxzsK7klm1c+J9kXXivYxj4hyLwmoc/mnARMtYV7cTQvDbUEzgRQmPykWKBv6Y0SL1WprfiRfKIMwSqQk91ffj6whKxBLAuUdseVBmo/ivLPq0a+wDrcvaJAxSB4eIwCHzAugkRA/NoK0vG3mra0lK5jvQrcNIuffxNAnresDVDTnYRc42etjePLAhlpeK/4sjYE/wPdeP8yzLHUg/hsSpAPIjLXJNZqUBAoGBANxPmUQNf1lGHo/nLY3dVMD3+kYNnTUD8XwS81qdg8/dNyF8t+7DOdJ1j7Itb+zGA1XXAGfTm6JoUG+eKKR2OSuyZcxygpOgzxAFanXKhTWZsKbG70xNmX0sOAEhtTGsgFTEGEv977MwIlFa6n2bsp3Luj/AGmvNsOYvBDPXOklxAoGBANXZyXAaE7M5JALusLuEFxLGvWVz6TRdQ//c+FWvKrnh+nFlTlAPpDvlaPJJca8ViNevxJ2UhGtbENXAqgwTYpnAi/yQD4dATViIveK6Pn4t12mpPAlkMbbMTR8jtp5l1oHchcwe8QuEOKuTX5+STpNGlWs+tsMb12mhCpc3eO3RAoGAMxjDE2WOA8afkACuMBkFbzwUb+r4azNe7sf2aS3fRHaqMroabuYYoxdhHJItQ10pqN8U2P/bOO+4uCqWgo5o9BmMQr7MSjEh1TVsW6V8/9GFhyjcl3XoA4Ad/SU0QTEhEofomrdqwMSJMRVFDZzu8Gov6FlFx3sNbFW7Q8rHWgECgYEAq/TVz3iIgsLdvCXmosHSM9zvCpcr3FlqhmFOpseVmaamVWxajnIlY6xSuRBpg5nTUWwas4Nq/1BYtyiXE+K6lFuJtOq6Mc145EoANkIAYkHGR0Y36m1QtGaPVQzImZHV7NJAHCR9Ov90+jIk4BErca1+FKB3IWhPzLYb6ABJEyECgYEAthhzWSxPkqyiLl+2vnhdR3EEkvDX6MV6hGu4tDAf2A1Y0GSApyEaSAA31hlxu5EgneLD7Ns2HMpIfQMydB5lcwKQc9g/tVI1eRzuk6Myi+2JmPEM2BLyiX8yI+xnZlKDiZleQitCS4RQGz5HbXT70aYQIGxuvkQ/uf68jdrL6o8="
-		},
-		"destinations": [
-			"/retrieve/ucar"
-		]
-	}
+  "global": {
+    "catalogPrefix": "/catalog",
+    "faceConfig": {
+      "host": "atmos-nwsc.ucar.edu",
+      "port": 9696
+    }
+  },
+  "retrieval": {
+    "demoKey": {
+      "pub": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuAmnWYKE7E8G+hyy4TiTU7t91KyIGvglEeT6HWEkW4LKzXLO22a1jVS9+yP96I6vp7N5vpS1t7oXtgWuzkO+O85u6gfbvwp+67zJe2I89eHO4dmNnP4fx/j7WcCUCyzZfbyW67h5IoouoBIdQge2Xdvh9rFdex9UUhyjEZv5676zlcqlhz8xGBrJmQHsqpD9ijY1XhKBvoSIoQ0ZKkpmwVk8QYM9PbjUqzSQBj4aYXS+BPV6aRudVvyDt2DBXp2FNP0CGrosCXKnSl4Yv8BYp0k0RmFZDuJuntLb/XIvPEfMX5li7g3zHzAlIJIVSwT+FRkd3H5cECFSIZFUYIuSQQIDAQAB",
+      "priv": "MIIEpQIBAAKCAQEAuAmnWYKE7E8G+hyy4TiTU7t91KyIGvglEeT6HWEkW4LKzXLO22a1jVS9+yP96I6vp7N5vpS1t7oXtgWuzkO+O85u6gfbvwp+67zJe2I89eHO4dmNnP4fx/j7WcCUCyzZfbyW67h5IoouoBIdQge2Xdvh9rFdex9UUhyjEZv5676zlcqlhz8xGBrJmQHsqpD9ijY1XhKBvoSIoQ0ZKkpmwVk8QYM9PbjUqzSQBj4aYXS+BPV6aRudVvyDt2DBXp2FNP0CGrosCXKnSl4Yv8BYp0k0RmFZDuJuntLb/XIvPEfMX5li7g3zHzAlIJIVSwT+FRkd3H5cECFSIZFUYIuSQQIDAQABAoIBAQCKBftzfxavn6lM5T8m+GZN0vzRBsBg8Z/jpsYKSLOayiHNKYCIPaSFpXuCIYEo6/JDJLB2xVLvwupLgkGSwm2mrvCyJkihI38Cz6iQF6I+iia9bYrupgwxzsK7klm1c+J9kXXivYxj4hyLwmoc/mnARMtYV7cTQvDbUEzgRQmPykWKBv6Y0SL1WprfiRfKIMwSqQk91ffj6whKxBLAuUdseVBmo/ivLPq0a+wDrcvaJAxSB4eIwCHzAugkRA/NoK0vG3mra0lK5jvQrcNIuffxNAnresDVDTnYRc42etjePLAhlpeK/4sjYE/wPdeP8yzLHUg/hsSpAPIjLXJNZqUBAoGBANxPmUQNf1lGHo/nLY3dVMD3+kYNnTUD8XwS81qdg8/dNyF8t+7DOdJ1j7Itb+zGA1XXAGfTm6JoUG+eKKR2OSuyZcxygpOgzxAFanXKhTWZsKbG70xNmX0sOAEhtTGsgFTEGEv977MwIlFa6n2bsp3Luj/AGmvNsOYvBDPXOklxAoGBANXZyXAaE7M5JALusLuEFxLGvWVz6TRdQ//c+FWvKrnh+nFlTlAPpDvlaPJJca8ViNevxJ2UhGtbENXAqgwTYpnAi/yQD4dATViIveK6Pn4t12mpPAlkMbbMTR8jtp5l1oHchcwe8QuEOKuTX5+STpNGlWs+tsMb12mhCpc3eO3RAoGAMxjDE2WOA8afkACuMBkFbzwUb+r4azNe7sf2aS3fRHaqMroabuYYoxdhHJItQ10pqN8U2P/bOO+4uCqWgo5o9BmMQr7MSjEh1TVsW6V8/9GFhyjcl3XoA4Ad/SU0QTEhEofomrdqwMSJMRVFDZzu8Gov6FlFx3sNbFW7Q8rHWgECgYEAq/TVz3iIgsLdvCXmosHSM9zvCpcr3FlqhmFOpseVmaamVWxajnIlY6xSuRBpg5nTUWwas4Nq/1BYtyiXE+K6lFuJtOq6Mc145EoANkIAYkHGR0Y36m1QtGaPVQzImZHV7NJAHCR9Ov90+jIk4BErca1+FKB3IWhPzLYb6ABJEyECgYEAthhzWSxPkqyiLl+2vnhdR3EEkvDX6MV6hGu4tDAf2A1Y0GSApyEaSAA31hlxu5EgneLD7Ns2HMpIfQMydB5lcwKQc9g/tVI1eRzuk6Myi+2JmPEM2BLyiX8yI+xnZlKDiZleQitCS4RQGz5HbXT70aYQIGxuvkQ/uf68jdrL6o8="
+    },
+    "destinations": [
+      "/retrieve/ucar"
+    ]
+  }
 }
diff --git a/client/catalog-dev/js/catalog.js b/client/catalog-dev/js/catalog.js
index 3e025b6..178ee18 100644
--- a/client/catalog-dev/js/catalog.js
+++ b/client/catalog-dev/js/catalog.js
@@ -1,83 +1,85 @@
 //Run when the document loads AND we have the config loaded.
-(function(){
+(function() {
   "use strict";
   var config;
   Promise.all([
-    new Promise(function(resolve, reject){
-      $.ajax('config.json').done(function(data){
-        config = data;
-        resolve();
-      }).fail(function(){
-        console.error("Failed to get config.");
-        ga('send', 'event', 'error', 'config');
-        reject();
-      });
-    }),
-    new Promise(function(resolve, reject){
-      var timeout = setTimeout(function(){
-        console.error("Document never loaded? Something bad has happened!");
-        reject();
-      }, 10000);
-      $(function () {
-        clearTimeout(timeout);
-        resolve();
-      });
-    })
-  ]).then(function(){
+  new Promise(function(resolve, reject) {
+    $.ajax('../config.json').done(function(data) {
+      config = data;
+      resolve();
+    }).fail(function() {
+      console.error("Failed to get config.");
+      ga('send', 'event', 'error', 'config');
+      reject();
+    });
+  }
+  ),
+  new Promise(function(resolve, reject) {
+    var timeout = setTimeout(function() {
+      console.error("Document never loaded? Something bad has happened!");
+      reject();
+    }, 10000);
+    $(function() {
+      clearTimeout(timeout);
+      resolve();
+    });
+  }
+  )
+  ]).then(function() {
 
-    var getParameterByName = function(name){
-          name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
-              var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
-                  results = regex.exec(location.search);
-            return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
-    };
+    var getParameterByName = function(name) {
+      name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+      var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
+      var results = regex.exec(location.search);
+      return results === null  ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+    }
 
     //Overwrite config if present. Any failure will just cause this to be skipped.
-    try{
+    try {
       var configParam = JSON.parse(getParameterByName('config'));
       config = jQuery.extend(true, config, configParam);
-    } catch(e){
+    } catch (e) {
       console.warn("Failure in config overwrite, skipping.", e);
     }
 
     new Atmos(config);
-  }, function(){
+  }, function() {
     console.error("Failed to initialize!");
     ga('send', 'event', 'error', 'init');
   });
 })();
 
-var Atmos = (function(){
+var Atmos = (function() {
   "use strict";
 
   var closeButton = '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
 
-  var guid = function(){
+  var guid = function() {
     var d = new Date().getTime();
     var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
-      var r = (d + Math.random()*16)%16 | 0;
-      d = Math.floor(d/16);
-      return (c=='x' ? r : (r&0x3|0x8)).toString(16);
+      var r = (d + Math.random() * 16) % 16 | 0;
+      d = Math.floor(d / 16);
+      return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
     });
     return uuid;
-  };
+  }
 
   /**
    * Atmos
    * @version 2.0
-   *
+
    * Configures an Atmos object. This manages the atmos interface.
-   *
+
    * @constructor
    * @param {string} catalog - NDN path
    * @param {Object} config - Object of configuration options for a Face.
    */
-  var Atmos = function(config){
+  var Atmos = function(config) {
 
     //Internal variables.
     this.results = [];
     this.resultCount = Infinity;
-    this.name = null;
+    this.name = null ;
     this.page = 0;
     this.resultsPerPage = 25;
     this.retrievedSegments = 0;
@@ -103,7 +105,7 @@
 
     var scope = this;
 
-    $('.requestSelectedButton').click(function(){
+    $('.requestSelectedButton').click(function() {
       ga('send', 'event', 'button', 'click', 'request');
       scope.request(scope.resultTable.find('.resultSelector:checked:not([disabled])').parent().parent());
     });
@@ -111,106 +113,113 @@
     this.filterSetup();
 
     //Init autocomplete
-    this.searchInput.autoComplete(function(field, callback){
+    this.searchInput.autoComplete(function(field, callback) {
       ga('send', 'event', 'search', 'autocomplete');
-      scope.autoComplete(field, function(data){
+      scope.autoComplete(field, function(data) {
         var list = data.next;
         var last = data.lastComponent === true;
-        callback(list.map(function(element){
-          return field + element + (last?"/":""); //Don't add trailing slash for last component.
+        callback(list.map(function(element) {
+          return field + element + (last ? "/" : "");
+          //Don't add trailing slash for last component.
         }));
       });
     });
 
     //Handle search
-    this.searchBar.submit(function(e){
+    this.searchBar.submit(function(e) {
       ga('send', 'event', 'search', 'submit');
       e.preventDefault();
-      if (scope.searchInput.val().length === 0){
-        if (!scope.searchBar.hasClass('has-error')){
+      if (scope.searchInput.val().length === 0) {
+        if (!scope.searchBar.hasClass('has-error')) {
           scope.searchBar.addClass('has-error').append('<span class="help-block">Search path is required!</span>');
         }
         return;
       } else {
-        scope.searchBar.removeClass('has-error').find('.help-block').fadeOut(function(){$(this).remove()});
+        scope.searchBar.removeClass('has-error').find('.help-block').fadeOut(function() {
+          $(this).remove()
+        });
       }
       scope.pathSearch();
     });
 
-    this.searchButton.click(function(){
+    this.searchButton.click(function() {
       console.log("Search Button Pressed");
       ga('send', 'event', 'button', 'click', 'search');
       scope.search();
     });
 
     //Result navigation handlers
-    this.resultMenu.find('.next').click(function(){
+    this.resultMenu.find('.next').click(function() {
       ga('send', 'event', 'button', 'click', 'next');
-      if (!$(this).hasClass('disabled')){
+      if (!$(this).hasClass('disabled')) {
         scope.getResults(scope.page + 1);
       }
     });
-    this.resultMenu.find('.previous').click(function(){
+    this.resultMenu.find('.previous').click(function() {
       ga('send', 'event', 'button', 'click', 'previous');
-      if (!$(this).hasClass('disabled')){
+      if (!$(this).hasClass('disabled')) {
         scope.getResults(scope.page - 1);
       }
     });
-    this.resultMenu.find('.clearResults').click(function(){
+    this.resultMenu.find('.clearResults').click(function() {
       ga('send', 'event', 'button', 'click', 'resultClear');
       scope.clearResults();
-      $('#results').fadeOut(function(){
+      $('#results').fadeOut(function() {
         $(this).addClass('hidden');
       });
     });
 
     //Change the number of results per page handler
-    var rpps = $('.resultsPerPageSelector').click(function(){
+    var rpps = $('.resultsPerPageSelector').click(function() {
 
       var t = $(this);
 
-      if (t.hasClass('active')){
+      if (t.hasClass('active')) {
         return;
       }
 
       rpps.find('.active').removeClass('active');
       t.addClass('active');
       scope.resultsPerPage = Number(t.text());
-      scope.getResults(0); //Force return to page 1;
+      scope.getResults(0);
+      //Force return to page 1;
 
     });
 
     //Init tree search
-    $('#treeSearch div').treeExplorer(function(path, callback){
+    $('#treeSearch div').treeExplorer(function(path, callback) {
       console.log("Tree Explorer request", path);
       ga('send', 'event', 'tree', 'request');
-      scope.autoComplete(path, function(data){
+      scope.autoComplete(path, function(data) {
         var list = data.next;
         var last = (data.lastComponent === true);
 
         if (last) {
           console.log("Redirecting last element request to a search.");
           scope.clearResults();
-          scope.query(scope.catalog, {'??': path},
-          function(interest, data){
+          scope.query(scope.catalog, {
+            '??': path
+          },
+          function(interest, data) {
             console.log("Search response", interest, data);
             scope.name = interest.getName();
             scope.getResults(0);
-          }, function(interest){
+          }, function(interest) {
             console.warn("Failed to retrieve final component.", interest, path);
             scope.createAlert("Failed to request final component. " + path + " See console for details.");
           });
-          return; //Don't call the callback
+          return;
+          //Don't call the callback
         }
 
         console.log("Autocomplete response", list);
-        callback(list.map(function(element){
-          return (path == "/"?"/":"") + element + "/";
+        callback(list.map(function(element) {
+          return (path == "/" ? "/" : "") + element + "/";
         }));
       });
     });
 
-    $('#treeSearch').on('click', '.treeSearch', function(){
+    $('#treeSearch').on('click', '.treeSearch', function() {
       var t = $(this);
 
       scope.clearResults();
@@ -219,17 +228,21 @@
 
       console.log("Tree search:", path);
 
-      scope.query(scope.catalog, {'??': path},
-      function(interest, data){ //Success
+      scope.query(scope.catalog, {
+        '??': path
+      },
+      function(interest, data) {
+        //Success
         console.log("Tree search response", interest, data);
 
         scope.name = interest.getName();
 
         scope.getResults(0);
       },
-      function(interest){ //Failure
+      function(interest) {
+        //Failure
         console.warn("Request failed! Timeout", interest);
-        scope.createAlert("Request timed out.\""+ interest.getName().toUri() + "\" See console for details.");
+        scope.createAlert("Request timed out.\"" + interest.getName().toUri() + "\" See console for details.");
       });
 
     });
@@ -237,8 +250,8 @@
     this.setupRequestForm();
 
     this.resultTable.popover({
-      selector : ".metaDataLink",
-      content: function(){
+      selector: ".metaDataLink",
+      content: function() {
         return scope.getMetaData(this);
       },
       title: "Metadata",
@@ -247,53 +260,56 @@
       placement: 'bottom'
     });
 
-    this.resultTable.on('click', '.metaDataLink', function(e){
+    this.resultTable.on('click', '.metaDataLink', function(e) {
       //This prevents the page from scrolling when you click on a name.
       e.preventDefault();
     });
 
-    this.resultTable.on('click', '.subsetButton', function(){
+    this.resultTable.on('click', '.subsetButton', function() {
       var metaData = $(this).siblings('pre').text();
       var exp = /netcdf ([\w-]+)/;
       var match = exp.exec(metaData);
-      var filename = match[0].replace(/netcdf /,'') + '.nc';
-      scope.request(null, filename);
+      var filename = match[0].replace(/netcdf /, '') + '.nc';
+      scope.request(null , filename);
     });
 
-  };
+  }
 
-  Atmos.prototype.clearResults = function(){
-    this.results = []; //Drop any old results.
+  Atmos.prototype.clearResults = function() {
+    this.results = [];
+    //Drop any old results.
     this.retrievedSegments = 0;
     this.resultCount = Infinity;
     this.page = 0;
     this.resultTable.empty();
-  };
+  }
 
-  Atmos.prototype.pathSearch = function(){
+  Atmos.prototype.pathSearch = function() {
     var value = this.searchInput.val();
 
     this.clearResults();
 
     var scope = this;
 
-    this.query(this.catalog, {"??": value},
-    function(interest, data){
+    this.query(this.catalog, {
+      "??": value
+    },
+    function(interest, data) {
       console.log("Query response:", interest, data);
 
-      scope.name = data.getName();
+      scope.name = interest.getName();
 
       scope.getResults(0);
 
     },
-    function(interest){
+    function(interest) {
       console.warn("Request failed! Timeout", interest);
       scope.createAlert("Request timed out. \"" + interest.getName().toUri() + "\" See console for details.");
     });
 
-  };
+  }
 
-  Atmos.prototype.search = function(){
+  Atmos.prototype.search = function() {
 
     var filters = this.getFilters();
 
@@ -306,77 +322,78 @@
     var scope = this;
 
     this.query(this.catalog, filters,
-    function(interest, data){ //Response function
+    function(interest, data) {
+      //Response function
       console.log("Query Response:", interest, data);
 
       scope.name = interest.getName();
 
       scope.getResults(0);
 
-    }, function(interest){ //Timeout function
+    }, function(interest) {
+      //Timeout function
       console.warn("Request failed after 3 attempts!", interest);
       scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details.");
     });
 
-  };
+  }
 
-  Atmos.prototype.autoComplete = function(field, callback){
+  Atmos.prototype.autoComplete = function(field, callback) {
 
     var scope = this;
 
-    this.query(this.catalog, {"?": field},
-    function(interest, data){
+    var result = {};
 
-      var name = interest.getName();
+    const getAll = function(interest, data) {
 
-      var interest = new Interest(name);
-      interest.setInterestLifetimeMilliseconds(1500);
-      interest.setMustBeFresh(true);
-
-      async.retry(4, function(done){
-        scope.face.expressInterest(interest,
-        function(interest, data){
-
-          if (data.getContent().length !== 0){
-            callback(JSON.parse(data.getContent().toString().replace(/[\n\0]/g, "")));
-            done();
-          } else {
-            callback([]);
-            done();
-          }
-
-        }, function(){
-          done("Failed attempt to request data.")
-        });
-      }, function(err, results){
-        if (err){
-          console.warn("Interest timed out!", interest);
-          scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details.");
+      if (data.getContent().length !== 0) {
+        var resp = JSON.parse(data.getContent().toString().replace(/[\n\0]/g, ""));
+        if (result.next) {
+          result.next = result.next.concat(resp.next);
+        } else {
+          result = resp;
         }
-      });
+      } else {
+        callback(result);
+      }
 
-    }, function(interest){
-      console.error("Request failed! Timeout", interest);
-      scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details.");
-    });
+      var name = data.getName();
+      var segment = name.components[name.getComponentCount() - 1];
+      if (segment.toSegment() !== data.getMetaInfo().getFinalBlockId().toSegment()){
+        name = name.getPrefix(-1); //Remove segment
+        name.appendSegment(segment.toSegment() + 1);
+        scope.expressInterest(name, getAll, function() {
+          console.warn("Autocomplete timed out, results may be incomplete.");
+          callback(result);
+          //Return if we get a timeout.
+        });
+      } else {
+        callback(result);
+      }
 
-  };
+    }
+
+    this.query(this.catalog, {
+      "?": field
+    }, getAll);
+
+  }
 
   Atmos.prototype.showResults = function(resultIndex) {
 
     var results = this.results.slice(this.resultsPerPage * resultIndex, this.resultsPerPage * (resultIndex + 1));
 
     var resultDOM = $(
-      results.reduce(function(prev, current){
-        prev.push('<tr><td><input class="resultSelector" type="checkbox"></td><td class="popover-container"><a href="#" class="metaDataLink">');
-        prev.push(current);
-        prev.push('</a></td></tr>');
-        return prev;
-      }, ['<tr><th><input id="resultSelectAll" type="checkbox" title="Select All"> Select</th><th>Name</th></tr>']).join('')
+    results.reduce(function(prev, current) {
+      prev.push('<tr><td><input class="resultSelector" type="checkbox"></td><td class="popover-container"><a href="#" class="metaDataLink">');
+      prev.push(current);
+      prev.push('</a></td></tr>');
+      return prev;
+    }, ['<tr><th><input id="resultSelectAll" type="checkbox" title="Select All"> Select</th><th>Name</th></tr>']).join('')
     );
 
-    resultDOM.find('#resultSelectAll').click(function(){
-      if ($(this).is(':checked')){
+    resultDOM.find('#resultSelectAll').click(function() {
+      if ($(this).is(':checked')) {
         resultDOM.find('.resultSelector:not([disabled])').prop('checked', true);
       } else {
         resultDOM.find('.resultSelector:not([disabled])').prop('checked', false);
@@ -390,35 +407,37 @@
 
     if (this.resultsPerPage * (resultIndex + 1) >= this.resultCount) {
       this.resultMenu.find('.next').addClass('disabled');
-    } else if (resultIndex === 0){
+    } else if (resultIndex === 0) {
       this.resultMenu.find('.next').removeClass('disabled');
     }
 
-    if (resultIndex === 0){
+    if (resultIndex === 0) {
       this.resultMenu.find('.previous').addClass('disabled');
     } else if (resultIndex === 1) {
       this.resultMenu.find('.previous').removeClass('disabled');
     }
 
-    $.scrollTo("#results", 500, {interrupt: true});
+    $.scrollTo("#results", 500, {
+      interrupt: true
+    });
 
-  };
+  }
 
-  Atmos.prototype.getResults = function(index){
+  Atmos.prototype.getResults = function(index) {
     var scope = this;
 
-    if ($('#results').hasClass('hidden')){
+    if ($('#results').hasClass('hidden')) {
       $('#results').removeClass('hidden').slideDown();
     }
 
-    if ((scope.results.length === scope.resultCount) || (scope.resultsPerPage * (index + 1) < scope.results.length)){
+    if ((scope.results.length === scope.resultCount) || (scope.resultsPerPage * (index + 1) < scope.results.length)) {
       //console.log("We already have index", index);
       scope.page = index;
       scope.showResults(index);
       return;
     }
 
-    if (scope.name === null) {
+    if (scope.name === null ) {
       console.error("This shouldn't be reached! We are getting results before a search has occured!");
       throw new Error("Illegal State");
     }
@@ -428,66 +447,51 @@
     // Interest name should be /<catalog-prefix>/query/<query-param>/<version>/<#seq>
     if (scope.name.size() === (scope.catalogPrefix.size() + 3)) {
       interestName = interestName.appendSegment(scope.retrievedSegments++);
-      console.log("Requesting data index: (", scope.retrievedSegments - 1, ") at ", interestName.toUri());
+      //console.log("Requesting data index: (", scope.retrievedSegments - 1, ") at ", interestName.toUri());
     }
 
-    var interest = new Interest(interestName);
+    this.expressInterest(interestName,
+    function(interest, data) {
+      //Response
 
-    interest.setInterestLifetimeMilliseconds(1500);
-    interest.setMustBeFresh(true);
-
-    async.retry(4, function(done){
-      scope.face.expressInterest(interest,
-        function(interest, data){ //Response
-
-          if (data.getContent().length === 0){
-            scope.resultMenu.find('.totalResults').text(0);
-            scope.resultMenu.find('.pageNumber').text(0);
-            scope.resultMenu.find('.pageLength').text(0);
-            console.log("Empty response.");
-            scope.resultTable.html("<tr><td>Empty response. This usually means no results.</td></tr>");
-            return;
-          }
-
-          var content = JSON.parse(data.getContent().toString().replace(/[\n\0]/g,""));
-
-          if (!content.results){
-            scope.resultMenu.find('.totalResults').text(0);
-            scope.resultMenu.find('.pageNumber').text(0);
-            scope.resultMenu.find('.pageLength').text(0);
-            console.log("No results were found!");
-            scope.resultTable.html("<tr><td>No Results</td></tr>");
-            return;
-          }
-
-          scope.results = scope.results.concat(content.results);
-
-          scope.resultCount = content.resultCount;
-
-          scope.resultMenu.find('.totalResults').text(scope.resultCount);
-
-          scope.page = index;
-
-          // reset scope.name
-          scope.name = new Name(data.getName().getPrefix(scope.catalogPrefix.size() + 3));
-
-          scope.getResults(index); //Keep calling this until we have enough data.
-
-          done();
-
-        },
-        function(interest){ //Timeout
-          done("Failed to request results.");
-        }
-      );
-    }, function(err){
-      if (err){
-        console.error("Failed to retrieve results: timeout", interest);
-        scope.createAlert("Request failed after 3 attempts. \"" + interest.getName().toUri() + "\" See console for details.");
+      if (data.getContent().length === 0) {
+        scope.resultMenu.find('.totalResults').text(0);
+        scope.resultMenu.find('.pageNumber').text(0);
+        scope.resultMenu.find('.pageLength').text(0);
+        console.log("Empty response.");
+        scope.resultTable.html("<tr><td>Empty response. This usually means no results.</td></tr>");
+        return;
       }
-    });
 
-  };
+      var content = JSON.parse(data.getContent().toString().replace(/[\n\0]/g, ""));
+
+      if (!content.results) {
+        scope.resultMenu.find('.totalResults').text(0);
+        scope.resultMenu.find('.pageNumber').text(0);
+        scope.resultMenu.find('.pageLength').text(0);
+        console.log("No results were found!");
+        scope.resultTable.html("<tr><td>No Results</td></tr>");
+        return;
+      }
+
+      scope.results = scope.results.concat(content.results);
+
+      scope.resultCount = content.resultCount;
+
+      scope.resultMenu.find('.totalResults').text(scope.resultCount);
+
+      scope.page = index;
+
+      // reset scope.name
+      scope.name = new Name(data.getName().getPrefix(scope.catalogPrefix.size() + 3));
+
+      scope.getResults(index);
+      //Keep calling this until we have enough data.
+
+    }, function() {}//Ignore failure
+    );
+
+  }
 
   Atmos.prototype.query = function(prefix, parameters, callback, timeout) {
 
@@ -497,81 +501,90 @@
     var jsonString = JSON.stringify(parameters);
     queryPrefix.append(jsonString);
 
-    var queryInterest = new Interest(queryPrefix);
-    queryInterest.setInterestLifetimeMilliseconds(1500);
-    queryInterest.setMustBeFresh(true);
+    this.expressInterest(queryPrefix, callback, timeout);
 
-    var face = this.face;
+  }
 
-    async.retry(4, function(done){
-      face.expressInterest(queryInterest, function(interest, data){
-        callback(interest, data);
+
+  Atmos.prototype.expressInterest = function(name, success, failure) {
+
+    var interest = new Interest(name);
+    interest.setInterestLifetimeMilliseconds(1500);
+    interest.setMustBeFresh(true);
+
+    const face = this.face;
+
+    async.retry(4, function(done) {
+      face.expressInterest(interest, function(interest, data) {
         done();
-       }, function(interest){
-         done("Failed attempt to query results", interest);
-       });
-    }, function(err, interest){
-      if (err){
-        timeout(interest);
+        success(interest, data);
+      }, function(interest) {
+        done("Interest timed out 4 times.", interest);
+      });
+    }, function(err, interest) {
+      if (err) {
+        console.log(err, interest);
+        failure(interest);
       }
     });
 
-  };
+  }
 
   /**
    * This function returns a map of all the categories active filters.
    * @return {Object<string, string>}
    */
-  Atmos.prototype.getFilters = function(){
-    var filters = this.filters.children().toArray().reduce(function(prev, current){
+  Atmos.prototype.getFilters = function() {
+    var filters = this.filters.children().toArray().reduce(function(prev, current) {
       var data = $(current).text().split(/:/);
       prev[data[0]] = data[1];
       return prev;
-    }, {}); //Collect a map<category, filter>.
+    }, {});
+    //Collect a map<category, filter>.
     //TODO Make the return value map<category, Array<filter>>
     return filters;
-  };
+  }
 
   /**
    * Creates a closable alert for the user.
-   *
+
    * @param {string} message
    * @param {string} type - Override the alert type.
    */
   Atmos.prototype.createAlert = function(message, type) {
 
     var alert = $('<div class="alert"><div>');
-    alert.addClass(type?type:'alert-info');
+    alert.addClass(type ? type : 'alert-info');
     alert.text(message);
     alert.append(closeButton);
 
     this.alerts.append(alert);
-  };
+  }
 
   /**
    * Requests all of the names represented by the buttons in the elements list.
-   *
+
    * @param elements {Array<jQuery>} A list of the table row elements
    * @param subsetFileName {String} If present then do a subsetting request instead.
    */
-  Atmos.prototype.request = function(){
+  Atmos.prototype.request = function() {
 
     //Pseudo globals.
     var keyChain;
     var certificateName;
     var keyAdded = false;
 
-    return function(elements, subsetFilename){
+    return function(elements, subsetFilename) {
 
       var names = [];
-      $(elements).find('.metaDataLink').each(function(){
+      $(elements).find('.metaDataLink').each(function() {
         var name = $(this).text();
         names.push(name);
       });
 
       var subset = false;
 
-      if (!subsetFilename){
+      if (!subsetFilename) {
         $('#subsetting').hide();
       } else {
         $('#subsetting').show();
@@ -579,61 +592,68 @@
       }
 
       var scope = this;
-      this.requestForm.on('submit', function(e){ //This will be registered for the next submit from the form.
+      this.requestForm.on('submit', function(e) {
+        //This will be registered for the next submit from the form.
         e.preventDefault();
 
         $('#request .alert').remove();
 
         var variables = [];
-        if (subset){
-          $('#subsetVariables .row').each(function(){
+        if (subset) {
+          $('#subsetVariables .row').each(function() {
             var t = $(this);
             var values = {};
-            t.find('.values input').each(function(){
+            t.find('.values input').each(function() {
               var t = $(this);
               values[t.attr('name')] = t.val();
             });
-            variables.push({variable: t.find('.variable').val(), values: values});
+            variables.push({
+              variable: t.find('.variable').val(),
+              values: values
+            });
           });
         }
 
         //Form checking
         var dest = scope.requestForm.find('#requestDest .active');
-        if (dest.length !== 1){
+        if (dest.length !== 1) {
           var alert = $('<div class="alert alert-warning">A destination is required!' + closeButton + '<div>');
           $('#request > .panel-body').append(alert);
           return;
         }
 
-        $('#request').modal('hide');//Initial params are ok. We can close the form.
+        $('#request').modal('hide');
+        //Initial params are ok. We can close the form.
 
         scope.cleanRequestForm();
 
-        $(this).off(e); //Don't fire this again, the request must be regenerated
+        $(this).off(e);
+        //Don't fire this again, the request must be regenerated
 
         //Key setup
-        if (!keyAdded){
-          if (!scope.config.retrieval.demoKey || !scope.config.retrieval.demoKey.pub || !scope.config.retrieval.demoKey.priv){
+        if (!keyAdded) {
+          if (!scope.config.retrieval.demoKey || !scope.config.retrieval.demoKey.pub || !scope.config.retrieval.demoKey.priv) {
             scope.createAlert("This host was not configured to handle retrieval! See console for details.", 'alert-danger');
             console.error("Missing/invalid key! This must be configured in the config on the server.", scope.config.demoKey);
             return;
           }
 
           //FIXME base64 may or may not exist in other browsers. Need a new polyfill.
-          var pub = new Buffer(base64.toByteArray(scope.config.retrieval.demoKey.pub)); //MUST be a Buffer (Buffer != Uint8Array)
+          var pub = new Buffer(base64.toByteArray(scope.config.retrieval.demoKey.pub));
+          //MUST be a Buffer (Buffer != Uint8Array)
           var priv = new Buffer(base64.toByteArray(scope.config.retrieval.demoKey.priv));
 
           var identityStorage = new MemoryIdentityStorage();
           var privateKeyStorage = new MemoryPrivateKeyStorage();
-          keyChain = new KeyChain(new IdentityManager(identityStorage, privateKeyStorage),
-                        new SelfVerifyPolicyManager(identityStorage));
+          keyChain = new KeyChain(new IdentityManager(identityStorage,privateKeyStorage),
+          new SelfVerifyPolicyManager(identityStorage));
 
           var keyName = new Name("/retrieve/DSK-123");
           certificateName = keyName.getSubName(0, keyName.size() - 1)
-            .append("KEY").append(keyName.get(-1))
-            .append("ID-CERT").append("0");
+          .append("KEY").append(keyName.get(-1))
+          .append("ID-CERT").append("0");
 
-          identityStorage.addKey(keyName, KeyType.RSA, new Blob(pub, false));
+          identityStorage.addKey(keyName, KeyType.RSA, new Blob(pub,false));
           privateKeyStorage.setKeyPairForKeyName(keyName, KeyType.RSA, pub, priv);
 
           scope.face.setCommandSigningInfo(keyChain, certificateName);
@@ -646,62 +666,61 @@
         var retrievePrefix = new Name("/catalog/ui/" + guid());
 
         scope.face.registerPrefix(retrievePrefix,
-          function(prefix, interest, face, interestFilterId, filter){ //On Interest
-            //This function will exist until the page exits but will likely only be used once.
+        function(prefix, interest, face, interestFilterId, filter) {
+          //On Interest
+          //This function will exist until the page exits but will likely only be used once.
 
-            var data = new Data(interest.getName());
-            var content;
-            if (subset){
-              content = JSON.stringify({name: subsetFilename, subset: variables});
-            } else {
-              content = JSON.stringify(names);
-            }
-            //Blob breaks the data! Don't use it
-            data.setContent(content); //TODO Packetize this.
-            keyChain.sign(data, certificateName);
-
-            try {
-              face.putData(data);
-              console.log("Responded for", interest.getName().toUri(), data);
-              scope.createAlert("Data retrieval has initiated.", "alert-success");
-            } catch (e) {
-              console.error("Failed to respond to", interest.getName().toUri(), data);
-              scope.createAlert("Data retrieval failed.");
-            }
-
-          }, function(prefix){ //On fail
-            scope.createAlert("Failed to register the retrieval URI! See console for details.", "alert-danger");
-            console.error("Failed to register URI:", prefix.toUri(), prefix);
-          }, function(prefix, registeredPrefixId){ //On success
-            var name = new Name(dest.text());
-            name.append(prefix);
-            var interest = new Interest(name);
-            interest.setInterestLifetimeMilliseconds(1500);
-
-            async.retry(4, function(done){
-              scope.face.expressInterest(interest,
-                function(interest, data){ //Success
-                  console.log("Request for", name.toUri(), "succeeded.", interest, data);
-                  done();
-                },
-                function(){
-                  done("Failed to request from retrieve agent.");
-                }
-              );
-            }, function(err){
-              if (err){
-                console.error("Request for", name.toUri(), "timed out (3 times).", interest);
-                scope.createAlert("Request for " + name.toUri() + " timed out after 3 attempts. This means that the retrieve failed! See console for more details.");
-              }
+          var data = new Data(interest.getName());
+          var content;
+          if (subset) {
+            content = JSON.stringify({
+              name: subsetFilename,
+              subset: variables
             });
-
+          } else {
+            content = JSON.stringify(names);
           }
+          //Blob breaks the data! Don't use it
+          data.setContent(content);
+          //TODO Packetize this.
+          keyChain.sign(data, certificateName);
+
+          try {
+            face.putData(data);
+            console.log("Responded for", interest.getName().toUri(), data);
+            scope.createAlert("Data retrieval has initiated.", "alert-success");
+          } catch (e) {
+            console.error("Failed to respond to", interest.getName().toUri(), data);
+            scope.createAlert("Data retrieval failed.");
+          }
+
+        }, function(prefix) {
+          //On fail
+          scope.createAlert("Failed to register the retrieval URI! See console for details.", "alert-danger");
+          console.error("Failed to register URI:", prefix.toUri(), prefix);
+        }, function(prefix, registeredPrefixId) {
+          //On success
+          var name = new Name(dest.text());
+          name.append(prefix);
+
+          scope.expressInterest(name,
+          function(interest, data) {
+            //Success
+            console.log("Request for", name.toUri(), "succeeded.", interest, data);
+          },
+          function() {
+            console.warn("Failed to request from retrieve agent.");
+          }
+          );
+        }
         );
 
       });
-      $('#request').modal(); //This forces the form to be the only option.
+      $('#request').modal();
+      //This forces the form to be the only option.
 
-    };
+    }
+
   }();
 
   Atmos.prototype.filterSetup = function() {
@@ -711,33 +730,41 @@
 
     var scope = this;
 
-    this.getAll(prefix, function(data) { //Success
-      var raw = JSON.parse(data.replace(/[\n\0]/g, '')); //Remove null byte and parse
+    this.getAll(prefix, function(data) {
+      //Success
+      var raw = JSON.parse(data.replace(/[\n\0]/g, ''));
+      //Remove null byte and parse
 
       console.log("Filter categories:", raw);
 
-      $.each(raw, function(index, object){ //Unpack list of objects
-        $.each(object, function(category, searchOptions) { //Unpack category from object (We don't know what it is called)
+      $.each(raw, function(index, object) {
+        //Unpack list of objects
+        $.each(object, function(category, searchOptions) {
+          //Unpack category from object (We don't know what it is called)
           //Create the category
           var e = $('<li><a href="#">' + category.replace(/_/g, " ") + '</a><ul class="subnav nav nav-pills nav-stacked"></ul></li>');
 
           var sub = e.find('ul.subnav');
-          $.each(searchOptions, function(index, name){
+          $.each(searchOptions, function(index, name) {
             //Create the filter list inside the category
             var item = $('<li><a href="#">' + name + '</a></li>');
             sub.append(item);
-            item.click(function(){ //Click on the side menu filters
-              if (item.hasClass('active')){ //Does the filter already exist?
+            item.click(function() {
+              //Click on the side menu filters
+              if (item.hasClass('active')) {
+                //Does the filter already exist?
                 item.removeClass('active');
                 scope.filters.find(':contains(' + category + ':' + name + ')').remove();
-              } else { //Add a filter
+              } else {
+                //Add a filter
                 item.addClass('active');
                 var filter = $('<span class="label label-default"></span>');
                 filter.text(category + ':' + name);
 
                 scope.filters.append(filter);
 
-                filter.click(function(){ //Click on a filter
+                filter.click(function() {
+                  //Click on a filter
                   filter.remove();
                   item.removeClass('active');
                 });
@@ -747,13 +774,15 @@
           });
 
           //Toggle the menus. (Only respond when the immediate tab is clicked.)
-          e.find('> a').click(function(){
+          e.find('> a').click(function() {
             scope.categories.find('.subnav').slideUp();
             var t = $(this).siblings('.subnav');
-            if ( !t.is(':visible') ){ //If the sub menu is not visible
-              t.slideDown(function(){
+            if (!t.is(':visible')) {
+              //If the sub menu is not visible
+              t.slideDown(function() {
                 t.triggerHandler('focus');
-              }); //Make it visible and look at it.
+              });
+              //Make it visible and look at it.
             }
           });
 
@@ -762,24 +791,25 @@
         });
       });
 
-    }, function(interest){ //Timeout
+    }, function(interest) {
+      //Timeout
       scope.createAlert("Failed to initialize the filters!", "alert-danger");
       console.error("Failed to initialize filters!", interest);
       ga('send', 'event', 'error', 'filters');
     });
 
-  };
+  }
 
   /**
    * This function retrieves all segments in order until it knows it has reached the last one.
    * It then returns the final joined result.
-   *
+
    * @param prefix {String|Name} The ndn name we are retrieving.
    * @param callback {function(String)} if successful, will call the callback with a string of data.
    * @param failure {function(Interest)} if unsuccessful, will call failure with the last failed interest.
    * @param stop {boolean} stop if no finalBlock.
    */
-  Atmos.prototype.getAll = function(prefix, callback, failure, stop){
+  Atmos.prototype.getAll = function(prefix, callback, failure, stop) {
 
     var scope = this;
     var d = [];
@@ -787,33 +817,16 @@
     var name = new Name(prefix);
     var segment = 0;
 
-    var request = function(){
+    var request = function() {
 
       var n2 = new Name(name);
       n2.appendSegment(segment);
 
-      var interest = new Interest(n2);
-      interest.setInterestLifetimeMilliseconds(1500);
-      interest.setMustBeFresh(true); //Is this needed?
+      scope.expressInterest(n2, handleData, function() {});
+      //Forward to handleData and ignore error
+    }
 
-      async.retry(4, function(done){
-        scope.face.expressInterest(interest,
-          function(interest, data){
-            handleData(interest, data);
-            done();
-          }, function(){
-            done("Failed to get segment.");
-          }
-        );
-      }, function(err){
-        if (err){
-          console.log("Failed after 3 attempts:", err);
-        }
-      });
-
-    };
-
-    var handleData = function(interest, data){
+    var handleData = function(interest, data) {
 
       d.push(data.getContent().toString());
 
@@ -821,39 +834,40 @@
       var finalBlockStop = hasFinalBlock && stop;
 
       if (finalBlockStop ||
-      (!hasFinalBlock && interest.getName().get(-1).toSegment() == data.getMetaInfo().getFinalBlockId().toSegment())){
+      (!hasFinalBlock && interest.getName().get(-1).toSegment() == data.getMetaInfo().getFinalBlockId().toSegment())) {
         callback(d.join(""));
       } else {
         segment++;
         request();
       }
 
-    };
+    }
 
     request();
 
-  };
+  }
 
-  Atmos.prototype.cleanRequestForm = function(){
+  Atmos.prototype.cleanRequestForm = function() {
     $('#requestDest').prev().removeClass('btn-success').addClass('btn-default');
     $('#requestDropText').text('Destination');
     $('#requestDest .active').removeClass('active');
     $('#subsetMenu').attr('class', 'collapse');
     $('#subsetVariables').empty();
     $('#request .alert').alert('close').remove();
-  };
+  }
 
-  Atmos.prototype.setupRequestForm = function(){
+  Atmos.prototype.setupRequestForm = function() {
 
     var scope = this;
 
-    this.requestForm.find('#requestCancel').click(function(){
-      $('#request').unbind('submit') //Removes all event handlers.
-      .modal('hide'); //Hides the form.
+    this.requestForm.find('#requestCancel').click(function() {
+      $('#request').unbind('submit')//Removes all event handlers.
+      .modal('hide');
+      //Hides the form.
       scope.cleanRequestForm();
     });
 
-    var dests = $(this.config['retrieval']['destinations'].reduce(function(prev, current){
+    var dests = $(this.config['retrieval']['destinations'].reduce(function(prev, current) {
       prev.push('<li><a href="#">');
       prev.push(current);
       prev.push("</a></li>");
@@ -861,7 +875,7 @@
     }, []).join(""));
 
     this.requestForm.find('#requestDest').append(dests)
-    .on('click', 'a', function(e){
+    .on('click', 'a', function(e) {
       $('#requestDest .active').removeClass('active');
       var t = $(this);
       t.parent().addClass('active');
@@ -869,27 +883,27 @@
       $('#requestDest').prev().removeClass('btn-default').addClass('btn-success');
     });
 
-    var addVariable = function(selector){
-      var ele = $(selector).clone().attr('id','');
-      ele.find('.close').click(function(){
+    var addVariable = function(selector) {
+      var ele = $(selector).clone().attr('id', '');
+      ele.find('.close').click(function() {
         ele.remove();
       });
       $('#subsetVariables').append(ele);
-    };
+    }
 
-    $('#subsetAddVariableBtn').click(function(){
+    $('#subsetAddVariableBtn').click(function() {
       addVariable('#customTemplate');
     });
-    $('#subsetAddTimeVariable').click(function(){
+    $('#subsetAddTimeVariable').click(function() {
       addVariable('#timeTemplate');
     });
-    $('#subsetAddLocVariable').click(function(){
+    $('#subsetAddLocVariable').click(function() {
       addVariable('#locationTemplate');
     });
 
-  };
+  }
 
-  Atmos.prototype.getMetaData = (function(){
+  Atmos.prototype.getMetaData = (function() {
 
     var cache = {};
 
@@ -905,10 +919,11 @@
       }
 
       var prefix = new Name(name).append("metadata");
-      var id = guid(); //We need an id because the return MUST be a string.
+      var id = guid();
+      //We need an id because the return MUST be a string.
       var ret = '<div id="' + id + '"><span class="fa fa-spinner fa-spin"></span></div>';
 
-      this.getAll(prefix, function(data){
+      this.getAll(prefix, function(data) {
         var el = $('<pre class="metaData"></pre>');
         el.text(data);
         var container = $('<div></div>');
@@ -916,14 +931,14 @@
         container.append(el);
         $('#' + id).empty().append(container);
         cache[name] = data;
-      }, function(interest){
+      }, function(interest) {
         $('#' + id).text("The metadata is unavailable for this name.");
         console.log("Data is unavailable for " + name);
       });
 
       return ret;
 
-    };
+    }
   })();
 
   return Atmos;
