diff --git a/metatag.admin.inc b/metatag.admin.inc
index 73b7e36..e169644 100644
--- a/metatag.admin.inc
+++ b/metatag.admin.inc
@@ -5,29 +5,6 @@
  * Administration page callbacks for the metatag module.
  */
 
-function _metatag_config_sort($a, $b) {
-  $return = NULL;
-  $a_contexts = explode(':', $a->instance);
-  $b_contexts = explode(':', $b->instance);
-  for ($i = 0; $i < max(count($a_contexts), count($b_contexts)); $i++) {
-    $a_context = isset($a_contexts[$i]) ? $a_contexts[$i] : '';
-    $b_context = isset($b_contexts[$i]) ? $b_contexts[$i] : '';
-    if ($a_context == $b_context) {
-      continue;
-    }
-    elseif ($a_context == 'global') {
-      $return = -1;
-    }
-    elseif ($a_context == '') {
-      $return = -1;
-    }
-    else {
-      $return = strcmp($a_context, $b_context);
-    }
-  }
-  return $return;
-}
-
 function _metatag_config_overview_indent($text, $instance) {
   $parents = metatag_config_get_parent_instances($instance);
   array_shift($parents);
@@ -48,8 +25,7 @@ function metatag_config_overview() {
   $metatags = metatag_get_info('tags');
 
   $configs = ctools_export_crud_load_all('metatag_config');
-  ksort($configs);
-  //uasort($configs, '_metatag_config_sort');
+  uksort($configs, '_metatag_config_instance_sort');
 
   $rows = array();
   foreach ($configs as $config) {
diff --git a/metatag.module b/metatag.module
index 7f70765..9bca95e 100644
--- a/metatag.module
+++ b/metatag.module
@@ -2625,3 +2625,31 @@ function metatag_taxonomy_vocabulary_delete($info) {
 function metatag_workbench_moderation_transition($node, $previous_state, $new_state) {
   metatag_metatags_cache_clear('node', array($node->nid));
 }
+
+/**
+ * sort callback for sorting by metatag instance string values.
+ */
+function _metatag_config_instance_sort($a, $b) {
+  $a_contexts = explode(':', $a);
+  $b_contexts = explode(':', $b);
+
+  // Global config always comes first.
+  if ($a_contexts[0] == 'global' && $b_contexts[0] != 'global') {
+    return -1;
+  }
+  elseif ($b_contexts[0] == 'global' && $a_contexts[0] != 'global') {
+    return 1;
+  }
+
+  for ($i = 0; $i < max(count($a_contexts), count($b_contexts)); $i++) {
+    $a_context = isset($a_contexts[$i]) ? $a_contexts[$i] : '';
+    $b_context = isset($b_contexts[$i]) ? $b_contexts[$i] : '';
+    if ($a_context == $b_context) {
+      continue;
+    }
+    else {
+      return strcmp($a_context, $b_context);
+      break;
+    }
+  }
+}
diff --git a/tests/metatag.unit.test b/tests/metatag.unit.test
index 3f5d0c6..251528d 100644
--- a/tests/metatag.unit.test
+++ b/tests/metatag.unit.test
@@ -127,4 +127,30 @@ class MetatagUnitTest extends MetatagTestHelper {
       $this->assertEqual($actual_output, $expected_output);
     }
   }
+
+  /**
+   * Test the _metatag_config_instance_sort() function.
+   */
+  public function testConfigInstanceSort() {
+    $input = array(
+      'node:article',
+      'global:frontpage',
+      'file',
+      'node:page',
+      'global',
+      'node',
+      'global:404',
+    );
+    usort($input, '_metatag_config_instance_sort');
+    $this->assertIdentical($input, array(
+      'global',
+      'global:404',
+      'global:frontpage',
+      'file',
+      'node',
+      'node:article',
+      'node:page',
+    ));
+  }
+
 }
