diff --git a/contextual.module b/contextual.module
index 589a0eb..337f230 100644
--- a/contextual.module
+++ b/contextual.module
@@ -55,7 +55,14 @@ function contextual_get_all_links($object, $type) {
     $links = contextual_prepare_links($links);
 
     if (!empty($links)) {
-      asort($links);
+      uasort($links, function($a, $b) {
+        $a_weight = (is_array($a) && isset($a['weight'])) ? $a['weight'] : 0;
+        $b_weight = (is_array($b) && isset($b['weight'])) ? $b['weight'] : 0;
+        if ($a_weight == $b_weight) {
+          return 0;
+        }
+        return ($a_weight < $b_weight) ? -1 : 1;
+      });
       contextual_add_css_and_js();
       return $links;
     }
