diff --git a/includes/common.inc b/includes/common.inc
index e078d68..961ca51 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -2773,7 +2773,10 @@ function drupal_add_css($data = NULL, $options = NULL) {
     );
 
     // Always add a tiny value to the weight, to conserve the insertion order.
-    $options['weight'] += count($css) / 1000;
+    $options['insertion_order'] = $options['weight'] + count($css)/1000;
+
+    // Always add a tiny value to the weight, to conserve the insertion order.
+    //$options['weight'] += count($css) / 1000;
 
     // Add the data to the CSS array depending on the type.
     switch ($options['type']) {
@@ -2822,9 +2825,8 @@ function drupal_get_css($css = NULL) {
   // Allow modules and themes to alter the CSS items.
   drupal_alter('css', $css);
 
-  // Sort CSS items according to their weights.
-  uasort($css, 'drupal_sort_weight');
-
+  // Sort CSS items according to their insertion order.
+  uasort($css, 'drupal_sort_insertion_order');
   // Remove the overridden CSS files. Later CSS files override former ones.
   $previous_item = array();
   foreach ($css as $key => $item) {
@@ -2897,6 +2899,9 @@ function drupal_group_css($css) {
     // that's different is that order.
     ksort($item['browsers']);
 
+    // Sort by weight to get sensible grouping for aggregation
+    ksort($item['weight']);
+
     // If the item can be grouped with other items, set $group_keys to an array
     // of information that must be the same for all items in its group. If the
     // item can't be grouped with other items, set $group_keys to FALSE. We
@@ -5490,6 +5495,18 @@ function drupal_sort_weight($a, $b) {
 }
 
 /**
+ * Function used by uasort to sort structured arrays by insertion_order, without the property weight prefix.
+ */
+function drupal_sort_insertion_order($a, $b) {
+  $a_insertion_order = (is_array($a) && isset($a['insertion_order'])) ? $a['insertion_order'] : 0;
+  $b_insertion_order = (is_array($b) && isset($b['insertion_order'])) ? $b['insertion_order'] : 0;
+  if ($a_insertion_order == $b_insertion_order) {
+    return 0;
+  }
+  return ($a_insertion_order < $b_insertion_order) ? -1 : 1;
+}
+
+/**
  * Check if the key is a property.
  */
 function element_property($key) {
