diff --git a/advagg_bundler/advagg_bundler.module b/advagg_bundler/advagg_bundler.module
index ec41b59..10af281 100644
--- a/advagg_bundler/advagg_bundler.module
+++ b/advagg_bundler/advagg_bundler.module
@@ -25,8 +25,8 @@ define('ADVAGG_BUNDLER_MAX_JS', 4);
 define('ADVAGG_BUNDLER_OUTDATED', 1209600);
 
 /**
- * Default value of the last used time before the bundle is considered outdated.
- * 2 weeks in seconds.
+ * Default value to see if the bundler should be active or passive. If it is
+ * passive, the bundler will only do analysis and not split up the aggregate.
  */
 define('ADVAGG_BUNDLER_ACTIVE', TRUE);
 
@@ -55,13 +55,13 @@ function advagg_bundler_menu() {
  * Implement hook_advagg_filenames_alter.
  */
 function advagg_bundler_advagg_filenames_alter(&$filenames) {
-
+  // Get max number of sub aggregates to create.
   $max_css = variable_get('advagg_bundler_max_css', ADVAGG_BUNDLER_MAX_CSS);
   $max_js = variable_get('advagg_bundler_max_js', ADVAGG_BUNDLER_MAX_JS);
 
   $output = array();
   foreach ($filenames as $values) {
-    // Set values.
+    // Extract values and set them.
     $filetype = $values['filetype'];
     $files = $values['files'];
     $bundle_md5 = $values['bundle_md5'];
@@ -74,12 +74,17 @@ function advagg_bundler_advagg_filenames_alter(&$filenames) {
       continue;
     }
 
+    // If cache miss then start to do processing.
+    // Set the max value based off of the filetype.
     if ($filetype == 'css') {
       $max = $max_css;
     }
     if ($filetype == 'js') {
       $max = $max_js;
     }
+
+    // If we are only going to have one bundle then do not do any more
+    // processing.
     if (empty($max) || $max == 1) {
       $output[] = $values;
       $data = array($values);
@@ -94,16 +99,22 @@ function advagg_bundler_advagg_filenames_alter(&$filenames) {
     foreach ($files as $key => $filename) {
       // Assign each file to their group.
       $group = advagg_bundler_analysis($filename);
+
+      // Set $last_group if this is the first run of this foreach loop.
       if (empty($last_group)) {
         $last_group = $group;
       }
 
       if ($last_group == $group) {
+        // Include this new file into the last used group.
         $groupings[$group][] = $filename;
       }
       else {
+        // In order to preserve CSS/JS execution order we need to move the last
+        // group to a unique name. Use the array key to make this group unique.
         $groupings[$key . ' ' . $last_group] = $groupings[$last_group];
         unset($groupings[$last_group]);
+        // Place the new file into the new group and set $last_group.
         $groupings[$group][] = $filename;
         $last_group = $group;
       }
@@ -121,8 +132,8 @@ function advagg_bundler_advagg_filenames_alter(&$filenames) {
     // together.
     advagg_bundler_merge($groupings, $max);
 
-
-    // If only one group then don't do any more processing.
+    // If only one group then don't do any more processing. The merge algorithm
+    // could have reduce the groupings down to one.
     if (count($groupings) == 1) {
       $output[] = $values;
       $data = array($values);
@@ -156,9 +167,21 @@ function advagg_bundler_advagg_filenames_alter(&$filenames) {
  *   string to be used for the grouping key.
  */
 function advagg_bundler_analysis($filename = '') {
-  static $analysis;
+  // Cache query in a static.
+  static $analysis = array();
   if (empty($analysis)) {
-    $analysis = array();
+    // "Magic Query"; only needs to run once.
+    // Return a count of how many root bundles all files are used in. Count is
+    // padded with eight zeros so the count can be key sorted as a string
+    // without worrying about it getting put in the wrong order.
+    // Return the bundle_md5's value; we need something more unique than count
+    // when grouping together.
+    // Return the filename. Used for lookup.
+    // We join the advagg bundles and files together making sure to only use
+    // root bundles that have been used in the last 2 weeks. This prevents an
+    // old site structure from influencing new bundles.
+    // Grouping by the filename gives us the count and makes it so we don't
+    // return a lot of rows;
     $result = db_query("
       SELECT
         LPAD(COUNT(*), 8, '00000000') AS count,
@@ -171,19 +194,24 @@ function advagg_bundler_analysis($filename = '') {
       GROUP BY ( af.filename )
     ", time() - variable_get('advagg_bundler_outdated', ADVAGG_BUNDLER_OUTDATED));
 
-    $counter = array();
+    // Save query into a static array with the filename as the key.
     while ($row = db_fetch_array($result)) {
       $analysis[$row['filename']] = $row['count'] . ' ' . $row['bundle_md5'];
     }
   }
 
+  // If no filename is given pass back then entire query results.
   if (empty($filename)) {
     return $analysis;
   }
 
+  // Return a key to be used in groupings.
   if (!empty($analysis[$filename])) {
     return $analysis[$filename];
   }
+
+  // We need to return a value that can be used as an array key if the query
+  // didn't give us anything.
   return 0;
 }
 
@@ -204,30 +232,45 @@ function advagg_bundler_merge(&$groupings, $max) {
     // Keep going till array has been merged to the desired size.
     while ($group_count > $max) {
       // Get array sizes.
+      // Counts the number of files that are placed into each bundle.
       $counts = array();
       foreach ($groupings as $key => $values) {
         $counts[$key] = count($values);
       }
 
       // Create mapping.
+      // Calculates the file count of potential merges. It only merges with
+      // neighbors in order to preserve execution order.
       $map = array();
       $prev_key = '';
       foreach ($counts as $key => $val) {
+        // First run of the foreach loop; populate prev key/values and continue.
+        // We can't merge with the previous group in this case.
         if (empty($prev_key)) {
           $prev_key = $key;
           $prev_val = $val;
           continue;
         }
-        $map[] = array(($prev_val + $val) => array($prev_key, $key));
+
+        // Array key ($prev_val + $val) is the file count of this new group if
+        // these 2 groups ($prev_key, $key) where to be merged together.
+        $map[] = array(
+          ($prev_val + $val) => array($prev_key, $key),
+        );
         $prev_key = $key;
         $prev_val = $val;
-       }
+      }
 
       // Get best merge candidate.
+      // We are looking for the smallest file count. $min is populated with a
+      // large number (15 bits) so it won't be selected in this process.
       $min = 32767;
       foreach ($map as $v) {
         foreach ($v as $key => $values) {
           $min = min($min, $key);
+          // If the min value (number of files in the proposed merged bundle) is
+          // the same as the key, then get the 2 bundle keys that generated this
+          // new min value.
           if ($min == $key) {
             list($first, $last) = $values;
           }
@@ -236,10 +279,12 @@ function advagg_bundler_merge(&$groupings, $max) {
 
 //       watchdog('debug', $first . "<br>\n" . $last . "<br>\n" . str_replace('    ', '&nbsp;&nbsp;&nbsp;&nbsp;', nl2br(htmlentities(print_r(array($groupings, $map, $counts), TRUE)))));
 
-      // Move arrays around.
+      // Create the new merged set
       $a = $groupings[$first];
       $b = $groupings[$last];
       $new_set = array_merge($a, $b);
+
+      // Rebuild the array with the new set in the correct place.
       $new_groupings = array();
       foreach ($groupings as $key => $files) {
         if ($key == $first) {
