diff --git a/database/database.mysql b/database/database.mysql
index e84d4518bc98798b7375962d109be05aec02e25a..68671f14bd6c322687844f5d417e2a70abaa91a2 100644
--- a/database/database.mysql
+++ b/database/database.mysql
@@ -685,7 +685,9 @@ CREATE TABLE system (
   throttle tinyint(1) DEFAULT '0' NOT NULL,
   bootstrap int(2) NOT NULL default '0',
   schema_version smallint(2) unsigned NOT NULL default 0,
-  PRIMARY KEY (filename)
+  weight int(2) NOT NULL default '0',
+  PRIMARY KEY (filename),
+  KEY (weight)
 ) TYPE=MyISAM;
 
 --
diff --git a/database/database.pgsql b/database/database.pgsql
index 8b7659f5a67964c6401a694ba2b53e7cca6dda40..1529901dd70a6d9d61c3d78e6817e8c282471e57 100644
--- a/database/database.pgsql
+++ b/database/database.pgsql
@@ -680,8 +680,10 @@ CREATE TABLE system (
   throttle smallint NOT NULL default '0',
   bootstrap integer NOT NULL default '0',
   schema_version smallint NOT NULL default 0,
+  weight smallint NOT NULL default 0,
   PRIMARY KEY (filename)
 );
+CREATE INDEX system_weight_idx ON system(weight);
 
 --
 -- Table structure for term_data
diff --git a/database/updates.inc b/database/updates.inc
index d4b440f3d6315650c27a6030ee1db58edb3ea3b1..10a73f3d7557e5eff511727c30aadedd10c17cdb 100644
--- a/database/updates.inc
+++ b/database/updates.inc
@@ -1397,3 +1397,19 @@ function system_update_166() {
 
   return $ret;
 }
+
+function system_update_167() {
+  $ret = array();
+  switch ($GLOBALS['db_type']) {
+    case 'pgsql':
+      db_add_column($ret, 'system', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0));
+      $ret[] = update_sql('CREATE INDEX {system}_weight_idx ON {system} (weight)');
+      break;
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("ALTER TABLE {system} ADD weight tinyint(3) unsigned default '0' NOT NULL, ADD KEY (weight)");
+      break;
+  }
+
+  return $ret;
+}
diff --git a/includes/module.inc b/includes/module.inc
index f4f5907725d78979354e296183646b6ac726c5d5..e4956999f0b265852606a63b609a00f991c2c296 100644
--- a/includes/module.inc
+++ b/includes/module.inc
@@ -50,10 +50,10 @@ function module_list($refresh = FALSE, $bootstrap = TRUE) {
   if (!$list) {
     $list = array('filter' => 'filter', 'system' => 'system', 'user' => 'user', 'watchdog' => 'watchdog');
     if ($bootstrap) {
-      $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1");
+      $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 AND bootstrap = 1 ORDER BY weight ASC, filename ASC");
     }
     else {
-      $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1");
+      $result = db_query("SELECT name, filename, throttle, bootstrap FROM {system} WHERE type = 'module' AND status = 1 ORDER BY weight ASC, filename ASC");
     }
     while ($module = db_fetch_object($result)) {
       if (file_exists($module->filename)) {
@@ -67,7 +67,6 @@ function module_list($refresh = FALSE, $bootstrap = TRUE) {
         }
       }
     }
-    asort($list);
   }
   return $list;
 }
diff --git a/modules/node.module b/modules/node.module
index 3c7283b0e3f18265dc112c8e9b8aedfe768671db..f7e998d131b1a4282234af6049b267eec862b269 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -2169,7 +2169,7 @@ function node_form_alter($form_id, &$form) {
  *   - "delete"
  *   - "create"
  * @param $node
- *   The node object (or node array) on which the operation is to be performed, 
+ *   The node object (or node array) on which the operation is to be performed,
  *   or node type (e.g. 'forum') for "create" operation.
  * @param $uid
  *   The user ID on which the operation is to be performed.
diff --git a/modules/node/node.module b/modules/node/node.module
index 3c7283b0e3f18265dc112c8e9b8aedfe768671db..f7e998d131b1a4282234af6049b267eec862b269 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -2169,7 +2169,7 @@ function node_form_alter($form_id, &$form) {
  *   - "delete"
  *   - "create"
  * @param $node
- *   The node object (or node array) on which the operation is to be performed, 
+ *   The node object (or node array) on which the operation is to be performed,
  *   or node type (e.g. 'forum') for "create" operation.
  * @param $uid
  *   The user ID on which the operation is to be performed.