diff --git a/core/includes/tablesort.inc b/core/includes/tablesort.inc
index 9cbfc3b..918ffb7 100644
--- a/core/includes/tablesort.inc
+++ b/core/includes/tablesort.inc
@@ -45,9 +45,9 @@ function tablesort_header($cell, $header, $ts) {
       // aria-sort is a WAI-ARIA property that indicates if items in a table
       // or grid are sorted in ascending or descending order. See
       // http://www.w3.org/TR/wai-aria/states_and_properties#aria-sort
-      $cell['aria-sort'] = ($ts['sort'] == 'asc') ? 'ascending' : 'descending';
+      $cell['attributes']['aria-sort'] = ($ts['sort'] == 'asc') ? 'ascending' : 'descending';
+      $cell['attributes']['class'][] = 'active';
       $ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
-      $cell['class'][] = 'active';
       $image = theme('tablesort_indicator', array('style' => $ts['sort']));
     }
     else {
@@ -81,10 +81,13 @@ function tablesort_header($cell, $header, $ts) {
 function tablesort_cell($cell, $header, $ts, $i) {
   if (isset($header[$i]['data']) && $header[$i]['data'] == $ts['name'] && !empty($header[$i]['field'])) {
     if (is_array($cell)) {
-      $cell['class'][] = 'active';
+      $cell['attributes']['class'][] = 'active';
     }
     else {
-      $cell = array('data' => $cell, 'class' => array('active'));
+      $cell = array(
+        'data' => $cell,
+        'attributes' => array('class' => array('active')),
+      );
     }
   }
   return $cell;
diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index f4b4957..5b7bc50 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -2105,7 +2105,7 @@ function theme_table($variables) {
 
   // Format the table columns:
   if (!empty($colgroups)) {
-    foreach ($colgroups as $number => $colgroup) {
+    foreach ($colgroups as $colgroup_key => $colgroup) {
 
       // Build colgroup
       if (is_array($colgroup['cols']) && !empty($colgroup['cols'])) {
@@ -2139,7 +2139,7 @@ function theme_table($variables) {
   // Format the table rows:
   if (!empty($rows)) {
     $output .= "<tbody>\n";
-    foreach ($rows as $number => $row) {
+    foreach ($rows as $row) {
       $cells = $row['cells'];
       if (!empty($cells)) {
 
@@ -2159,25 +2159,41 @@ function theme_table($variables) {
 }
 
 /**
- * Preprocess variables for theme_table().
+ * Preprocess variables for table templates.
  * @todo: update this once merged with head, and table.html.twig updated.
  */
 function template_preprocess_table(&$variables) {
-
-  // Table Attributes
+  // Flags.
+  $is_sticky = !empty($variables['sticky']);
+  $is_responsive = !empty($variables['responsive']);
+
+  // Table attributes.
+  // Note: Cast to Attribute() at the bottom.
+  // @todo: Find out why we can't cast to Attribute() here.
+  // i.e. $variables['attributes'] = new Attribute($variables['attributes']);
   $table_attributes = $variables['attributes'];
-  $is_sticky = $variables['sticky'];
-  $is_responsive = $variables['responsive'];
 
-  // Table Child Elements
+  // Table headers. (Drupal supports only one, that's why it's called 'header').
+  // Headers needed for reference of active sorting
+  // header after it's cells are processed
+  // array_values indexes for the table sort to work
+  // @todo: Clarify why this variable is used or fix to use variables['header'] directly.
+  if (!empty($variables['header']) && is_array($variables['header'])) {
+     $variables['header'] = array_values($variables['header']);
+  }
   $headers = $variables['header'];
-  $rows = $variables['rows'];
-  $colgroups = $variables['colgroups'];
 
-  // Empty Message
-  $empty_message = $variables['empty'];
+  // Empty message.
+  // Set to new variable for convenient checks later.
+  $empty_message = (isset($variables['empty'])) ? $variables['empty'] : '';
+  // Remove 'empty' from template variables and set message to it's own variable
+  // to make sure we don't conflict with Twig's reserved keyword of the same name.
+  unset($variables['empty']);
+  // @todo: API change, rename this variable from 'empty' to 'empty_message'.
+  $variables['empty_message'] = $empty_message;
 
-  if (!empty($headers)) {
+  // Preprocess header.
+  if (!empty($variables['header'])) {
     // Add sticky headers, if applicable.
     if ($is_sticky) {
       drupal_add_library('system', 'drupal.tableheader');
@@ -2197,14 +2213,12 @@ function template_preprocess_table(&$variables) {
     }
   }
 
-  // Format the table columns:
-  if (!empty($colgroups)) {
-    $variables['colgroups'] = array();
-    foreach ($colgroups as $number => $colgroup) {
-      $variables['colgroups'][$number] = array();
-      $colgroup_attributes = array();
+  // Preprocess colgroups.
+  if (!empty($variables['colgroups'])) {
+    foreach ($variables['colgroups'] as $colgroup_key => $colgroup) {
+      $colgroup_attributes = new Attribute(array());
 
-      // Check if we're dealing with a simple or complex colgroup
+      // Support simple or complex colgroups.
       if (isset($colgroup['data'])) {
         foreach ($colgroup as $key => $value) {
           if ($key == 'data') {
@@ -2219,25 +2233,26 @@ function template_preprocess_table(&$variables) {
         $cols = $colgroup;
       }
 
-      // Build colgroup
-      $variables['colgroups'][$number]['attributes'] = new Attribute($colgroup_attributes);
+      // Set colgroup attributes.
+      $variables['colgroups'][$colgroup_key]['attributes'] = $colgroup_attributes;
 
-      // Build cols within colgroup
+      // Set cols.
       if (is_array($cols) && !empty($cols)) {
-        $variables['colgroups'][$number]['cols'] = array();
+        $variables['colgroups'][$colgroup_key]['cols'] = array();
         foreach ($cols as $col_key => $col) {
           $col_attributes = new Attribute($col);
-          $variables['colgroups'][$number]['cols'][$col_key]['attributes'] = $col_attributes;
+          $variables['colgroups'][$colgroup_key]['cols'][$col_key]['attributes'] = $col_attributes;
         }
       }
     }
   }
 
-  // Add the 'empty' row message if available.
-  // @todo  Removed Let the Theme template do this and don't change the # of rows
-  if (empty($rows) && !empty($empty_message)) {
+  // Preprocess Empty message.
+  // Add one row spanning all columns for the 'empty' message if there are no
+  // data rows and the empty message is set.
+  if (empty($variables['rows']) && !empty($empty_message)) {
     $header_count = 0;
-    foreach ($headers as $header_cell) {
+    foreach ($variables['header'] as $header_cell) {
       if (is_array($header_cell)) {
         $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
       }
@@ -2245,70 +2260,99 @@ function template_preprocess_table(&$variables) {
         $header_count++;
       }
     }
-    $rows[] = array(array(
+    // Add one row for the empty message spanning all columns.
+    // @todo?: Leave rows empty, let template decide how to handle no rows,
+    // using empty_message variable and optionally counting the columns to
+    // generate an "empty" row spanning all columns like this.
+    $variables['rows'][] = array(array(
       'data' => $empty_message,
-      'colspan' => $header_count,
-      'class' => array('empty', 'message'),
+      'attributes' => new Attribute(array(
+        'colspan' => $header_count,
+        'class' => array('empty', 'message'),
+      ))
     ));
   }
 
+  // Build up an associative array of responsive classes keyed by column.
   $responsive_classes = array();
 
-  // Format the table header:
-  if (!empty($headers)) {
-    $ts = tablesort_init($headers);
-    $i = 0;
-    foreach ($headers as $key => $cell) {
-      $i++;
+  // Preprocess table header.
+  if (!empty($variables['header'])) {
+
+    // Initialize table sorting.
+    $ts = tablesort_init($variables['header']);
+
+    foreach ($variables['header'] as $col_key => $cell) {
+
+      // If the cell is not an array, make it one.
+      if (!is_array($cell)) {
+        $cell = array(
+          'data' => $cell,
+          'attributes' => array(),
+        );
+      }
+
+      // Create cell attributes
+      if (!isset($cell['attributes'])) {
+        $cell['attributes'] = array();
+      }
+
       // Track responsive classes for each column as needed. Only the header
       // cells for a column are marked up with the responsive classes by a
       // module developer or themer. The responsive classes on the header cells
       // must be transferred to the content cells.
       if (!empty($cell['class']) && is_array($cell['class'])) {
         if (in_array(RESPONSIVE_PRIORITY_MEDIUM, $cell['class'])) {
-          $responsive_classes[$i] = RESPONSIVE_PRIORITY_MEDIUM;
+          $responsive_classes[$col_key] = RESPONSIVE_PRIORITY_MEDIUM;
         }
         elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) {
-          $responsive_classes[$i] = RESPONSIVE_PRIORITY_LOW;
+          $responsive_classes[$col_key] = RESPONSIVE_PRIORITY_LOW;
         }
       }
 
-      // If the cell is not an array, make it one
-      if (!is_array($cell)) {
-        $cell = array('data' => $cell);
-      }
+      // @todo: Find out why we can use $variables['header'] here but must use
+      // $headers for tablesort_cell() below.
+      $cell = tablesort_header($cell, $variables['header'], $ts);
 
-      $cell = tablesort_header($cell, $headers, $ts);
+      // Support simple or complex cells.
+      // Doing this after tablesort_header because it removes it's sort and field values
+      foreach ($cell as $key => $value) {
+        if ($key != 'data' && $key != 'attributes') {
+          $cell['attributes'][$key] = $value;
+        }
+      }
 
-      // Tell the cell to be a header
+      // Flag the cell as a header.
       $cell['header'] = TRUE;
 
-      // Convert to the format table_cell preprocesser will accept
-      $cell = array('cell' => $cell);
-
-      $headers[$key] = $cell;
+      // Update the header cell with attributes and properties.
+      // @todo: Make sure we're not overwriting or losing any header element
+      // variables.
+      $variables['header'][$col_key] = $cell;
     }
   }
   else {
     $ts = array();
   }
 
-  // Format the table rows:
-  if (!empty($rows)) {
+  // Preprocess table rows.
+  if (!empty($variables['rows'])) {
 
-    // @todo replace this because zebras are for the zoo, see http://drupal.org/node/1649780
+    // Add odd/even class.
+    // @todo replace this because zebras are for the zoo.
+    // @see http://drupal.org/node/1649780
     $flip = array(
       'even' => 'odd',
       'odd' => 'even',
     );
     $class = 'even';
 
-    foreach ($rows as $number => $row) {
+    foreach ($variables['rows'] as $row_key => $row) {
 
       $row_attributes = array();
       $cells = array();
 
-      // Check if we're dealing with a simple or complex row
+      // Support simple or complex rows.
       if (isset($row['data'])) {
         foreach ($row as $key => $value) {
           if ($key == 'data') {
@@ -2323,56 +2367,66 @@ function template_preprocess_table(&$variables) {
         $cells = $row;
       }
 
-      // @todo replace this because zebras are for the zoo, see http://drupal.org/node/1649780
-      // Add odd/even class
+      // Add odd/even class.
+      // @todo replace this because zebras are for the zoo.
+      // @see http://drupal.org/node/1649780
       if (empty($row['no_striping'])) {
         $class = $flip[$class];
         $row_attributes['class'][] = $class;
       }
 
       if (!empty($cells)) {
-        // Build row
-        $variables['rows'][$number] = array();
-        $variables['rows'][$number]['attributes'] = new Attribute($row_attributes);
-        $variables['rows'][$number]['cells'] = array();
+        // Build row.
+        $variables['rows'][$row_key] = array();
+        $variables['rows'][$row_key]['attributes'] = new Attribute($row_attributes);
+        $variables['rows'][$row_key]['cells'] = array();
         $i = 0;
         foreach ($cells as $cell) {
-          $i++;
 
-          // If the cell is not an array, make it one
+          // If the cell is not an array, make it one.
           if (!is_array($cell)) {
-            $cell = array('data' => $cell);
+            $cell = array(
+              'data' => $cell,
+              'attributes' => array(),
+            );
+          }
+
+          // Create cell attributes
+          if (!isset($cell['attributes'])) {
+            $cell['attributes'] = array();
           }
 
           // Add active class if needed for sortable tables.
+          // @todo: Find out why we can't use $variables['header']
+          // instead of $headers here while we can in tablesort_header() above.
           $cell = tablesort_cell($cell, $headers, $ts, $i);
 
+          // Support simple or complex cells.
+          foreach ($cell as $key => $value) {
+            if ($key != 'data' && $key != 'attributes') {
+              $cell['attributes'][$key] = $value;
+            }
+          }
+
           // Copy RESPONSIVE_PRIORITY_LOW/RESPONSIVE_PRIORITY_MEDIUM
           // class from header to cell as needed.
           if (isset($responsive_classes[$i])) {
-            if (is_array($cell)) {
-              $cell['class'][] = $responsive_classes[$i];
-            }
+            $cell['attributes']['class'][] = $responsive_classes[$i];
           }
 
-          // Add the cell to the row
-          $variables['rows'][$number]['cells'][$i] = array();
-          $variables['rows'][$number]['cells'][$i]['cell'] = $cell;
+          // Add the cell to the row.
+          $variables['rows'][$row_key]['cells'][$i] = $cell;
+          $i++;
         }
       }
     }
   }
 
-  // Set the table attributes
+  // Table attributes.
+  // For some reason, this needs to be set here.
+  // ('Show all columns' disappears otherwise).
+  // @todo: Find out why it can't be set up top.
   $variables['attributes'] = new Attribute($table_attributes);
-
-  // Replace header with parsed header array
-  $variables['header'] = $headers;
-
-  // Remove empty from template variables and set message to it's own variable
-  // Not to conflict with twig's reserved keyword empty
-  unset($variables['empty']);
-  $variables['empty_message'] = $empty_message;
 }
 
 /**
@@ -2399,19 +2453,27 @@ function theme_tablesort_indicator($variables) {
  *   - style: Set to either 'asc' or 'desc'. This determines which icon to show.
  */
 function template_preprocess_tablesort_indicator(&$variables) {
-
+    // Provide the image attributes for an ascending or descending image
   if ($variables['style'] == 'asc') {
-    // Provide the image attributes for an ascending image
-    $variables['src'] = file_create_url('core/misc/arrow-asc.png');
-    $attributes = array('width' => 13, 'height' => 13, 'alt' => t('sort ascending'), 'title' => t('sort ascending'));
-  } else {
-    // Provide the image attributes for a descending image
-    $variables['src'] = file_create_url('core/misc/arrow-desc.png');
-    $attributes = array('width' => 13, 'height' => 13, 'alt' => t('sort descending'), 'title' => t('sort descending'));
+    $variables['uri'] = 'core/misc/arrow-asc.png';
+    $alt_title = t('sort ascending');
   }
+  else {
+    $variables['uri'] = 'core/misc/arrow-desc.png';
+    $alt_title = t('sort descending');
+  }
+  // Build the attributes to the indicator image
+  $attributes = array(
+    'width' => 13,
+    'height' => 13,
+    'src' => file_create_url($variables['uri']),
+    'alt' => $alt_title,
+    'title' => $alt_title,
+  );
   $variables['attributes'] = new Attribute($attributes);
 }
 
+
 /**
  * Returns HTML for a marker for new or updated content.
  *
@@ -2770,40 +2832,6 @@ function theme_indentation($variables) {
 }
 
 /**
- * @} End of "addtogroup themeable".
- */
-
-/**
- * Returns HTML output for a single table cell for theme_table().
- *
- * @param $cell
- *   Array of cell information, or string to display in cell.
- * @param bool $header
- *   TRUE if this cell is a table header cell, FALSE if it is an ordinary
- *   table cell. If $cell is an array with element 'header' set to TRUE, that
- *   will override the $header parameter.
- *
- * @return
- *   HTML for the cell.
- *
- * @todo remove this
- */
-function _theme_table_cell($cell, $header = FALSE) {
-  $is_header |= isset($cell['header']);
-  $data = (isset($cell['data'])) ? $cell['data'] : $cell;
-  $attributes = (isset($cell['attributes'])) ? $cell['attributes'] : '';
-
-  if ($is_header) {
-    $output = '<th' . $attributes . '>' . $data . '</th>';
-  }
-  else {
-    $output = '<td' . $attributes . '>' . $data . '</td>';
-  }
-
-  return $output;
-}
-
-/**
  * Returns HTML for a table cell.
  *
  * @param $variables
@@ -2826,48 +2854,38 @@ function theme_table_cell($variables) {
   return $output;
 }
 
+
+/**
+ * @} End of "addtogroup themeable".
+ */
+
 /**
  * Preprocess variables for theme_table_cell().
  */
 function template_preprocess_table_cell(&$variables) {
 
   // Initialize variables needed by template
-  $variables['header'] = isset($variables['cell']['header']) || FALSE;
+  $variables['header'] = isset($variables['header']) || FALSE;
   $variables['content'] = '';
-  $variables['attributes'] = new Attribute();
+  if (empty($variables['attributes'])) {
+    $variables['attributes'] = new Attribute();
+  }
+  else {
+    $variables['attributes'] = new Attribute($variables['attributes']);
+  }
 
   // Cells can be arrays or strings.
-  if (is_array($variables['cell']) ) {
-
-    if (isset($variables['cell']['data'])) {
-      // The cell's data element can be a render array or a string.
-      if (is_array($variables['cell']['data'])) {
-        $variables['content'] = drupal_render($variables['cell']['data']);
-      }
-      else {
-        $variables['content'] = $variables['cell']['data'];
-      }
-      // Unset the data element to avoid it appearing in the attributes.
-      unset($variables['cell']['data']);
+  if (isset($variables['data'])) {
+    // The cell's data element can be a render array or a string.
+    if (is_array($variables['data'])) {
+      $variables['content'] = drupal_render($variables['data']);
     }
-
-    // If the cell has a header element, set the header variable to its value.
-    if (isset($variables['cell']['header'])) {
-      $variables['header'] = $variables['cell']['header'];
-
-      // Unset the header element to avoid it appearing in the attributes.
-      unset($variables['cell']['header']);
+    else {
+      $variables['content'] = $variables['data'];
     }
-
-    // Generate attributes for this cell.
-    $variables['attributes'] = new Attribute($variables['cell']);
+    // Unset the data element to avoid it appearing in the attributes.
+    unset($variables['data']);
   }
-  else {
-    $variables['content'] = $variables['data'];
-  }
-  // Remove cell because theme_table_cell doesn't need it
-  unset($variables['cell']);
-
 }
 
 /**
@@ -3455,7 +3473,7 @@ function drupal_common_theme() {
       'variables' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL, 'colgroups' => array(), 'sticky' => TRUE, 'responsive' => TRUE, 'empty' => ''),
     ),
     'table_cell' => array(
-       'variables' => array('cell' => NULL, 'content' => NULL, 'header' => NULL, 'attributes' => array()),
+       'variables' => array('content' => NULL, 'header' => NULL, 'attributes' => array()),
     ),
     'meter' => array(
       'variables' => array('display_value' => NULL, 'form' => NULL, 'high' => NULL, 'low' => NULL, 'max' => NULL, 'min' => NULL, 'optimum' => NULL, 'value' => NULL, 'percentage' => NULL, 'attributes' => array()),
diff --git a/core/themes/stark/templates/theme.inc/table-cell.html.twig b/core/themes/stark/templates/theme.inc/table-cell.html.twig
index aee9fe7..3771249 100644
--- a/core/themes/stark/templates/theme.inc/table-cell.html.twig
+++ b/core/themes/stark/templates/theme.inc/table-cell.html.twig
@@ -4,7 +4,7 @@
  * Default theme implementation to display a table cell.
  *
  * Available variables:
- * - header: Whether this cell is a header cell or not.
+ * - header: Whether this cell is a th or td.
  * - content: The cell content.
  * - attributes: HTML attributes to apply to the cell.
  *
@@ -15,8 +15,9 @@
  * @ingroup themeable
  */
 #}
-<{{ header ? 'th' : 'td' }}{{ attributes }}>
-{%- if content -%}
-	{{ content }}
-{%- endif -%}
-</{{ header ? 'th' : 'td' }}>
\ No newline at end of file
+{% set tag = header ? 'th' : 'td' %}
+<{{ tag }}{{ attributes }}>
+  {% if content %}
+    {{ content }}
+  {% endif %}
+</{{ tag }}>
\ No newline at end of file
diff --git a/core/themes/stark/templates/theme.inc/table.html.twig b/core/themes/stark/templates/theme.inc/table.html.twig
index 1158f43..4e4492b 100644
--- a/core/themes/stark/templates/theme.inc/table.html.twig
+++ b/core/themes/stark/templates/theme.inc/table.html.twig
@@ -4,30 +4,29 @@
  * Default theme implementation to display a table.
  *
  * Available variables:
- * - header: The table headers. Each element of the array can be accessed
- *   with the following keys:
- *   - header.data: The localized title of the table column.
- *   - header.field: The database field represented in the table column
- *     (required if user is to be able to sort on this column).
- *   - header.sort: A default sort order for this column ("asc" or "desc").
- *   - header.attributes: Any html attributes, such as "colspan", to apply
- *     to the column header cell.
- * - rows: The table rows. Every row contains cells that can be accessed with
- *   the following keys:
- *   - row.data: the cells.
- *   - row.attributes: Any html attributes, such as "class", to apply to the
- *     table row.
- *   - row.no_striping: a flag indicating that the row should receive no
- *     'even / odd' styling. Defaults to FALSE.
+ * - attributes: HTML attributes to apply to the <table> tag.
+ * - caption: A localized string for the <caption> tag.
+ * - colgroups: Column groups. Each group contains the following properties:
+ *   - attributes: HTML attributes to apply to the <col> tag.
+ * // Note: Drupal currently supports only one table header row.
+ * // @see http://drupal.org/node/893530
+ * // @see http://api.drupal.org/api/drupal/includes!theme.inc/function/theme_table/7#comment-5109
+ * - header: Table header cells. Each cell contains the following properties:
+ *   - attributes: HTML attributes to apply to the <th> tag.
+ *   - data: A localized string for the title of the column.
+ *   - field: Field name (required for column sorting).
+ *   - sort: Default sort order for this column ("asc" or "desc").
+ * - sticky: A boolean flag indicating whether to use a "sticky" table header.
+ * - rows: Table rows. Each row contains the following properties:
+ *   - attributes: HTML attributes to apply to the <tr> tag.
+ *   - data: Table cells.
+ *   - no_striping: a flag indicating that the row should receive no
+ *     'even / odd' styling. Defaults to FALSE. // @todo: Deprecate no_striping?
  *     A cell can be either a string or may contain the following keys:
  *     - data: The string to display in the table cell.
  *     - header: Indicates this cell is a header.
  *     - attributes: Any html attributes, such as "colspan", to apply to the
  *       table cell.
- * - attributes: HTML attributes to apply to the table tag.
- * - caption: A localized string to use for the <caption> tag.
- * - colgroups: An array of column groups.
- * - sticky: Use a "sticky" table header.
  * - empty_message: The message to display in an extra row if table does not have any rows.
  *
  * @see template_preprocess
@@ -36,50 +35,56 @@
  * @ingroup themeable
  */
 #}
-
 <table{{ attributes }}>
+  {# Caption #}
   {% if caption %}
     <caption>{{ caption }}</caption>
   {% endif %}
 
-  {# Build the colgroup element. #}
+  {# Columns #}
   {% if colgroups %}
     {% for colgroup in colgroups %}
-     {% if colgroup.cols %}
-      <colgroup{{ colgroup.attributes }}>
-      {# 
-      Temporary Fix by http://drupal.org/node/1778968#comment-6820122 
-      col.attributes is getting stripped on second loop through 
-      #}
-      {% for i,col in colgroup.cols %}
-        <col{{ colgroup.cols[i].attributes }}/>
-      {% endfor %}
-       </colgroup>
-     {% else %}
-      <colgroup{{ colgroup.attributes }}/>
-     {% endif %}
-   {% endfor %}
- {% endif %}
+      {% if colgroup.cols %}
+        <colgroup{{ colgroup.attributes }}>
+        {% for col in colgroup.cols %}
+          {#
+            Use temporary variable for column attributes.  This somehow works
+            around the issue where columns after the first column do not receive
+            attributes.  Try using col.attributes directly, and you'll see.
+            Is this a Twig or an Attribute() issue?
+            @see http://drupal.org/node/1867090
+          #}
+          {% set col_attributes = col.attributes %}
+          <col{{ col.attributes }}/>
+        {% endfor %}
+         </colgroup>
+       {% else %}
+         <colgroup{{ colgroup.attributes }}/>
+      {% endif %}
+    {% endfor %}
+  {% endif %}
 
-  {# Build the table header. #}
+  {# Header #}
   {% if header %}
-    <thead><tr>
-    {% for cell in header %}
-      {{ theme('table_cell', cell) }} {# no th here since this calls table_cell #}
-    {% endfor %}
-    </tr></thead>
+    <thead>
+      <tr>
+      {%- for cell in header -%}
+        {{ theme('table_cell', cell) }} {# Note: <th> returned by table_cell. #}
+      {%- endfor -%}
+      </tr>
+    </thead>
   {% endif %}
 
-  {# Build the table rows. #}
+  {# Rows #}
   {% if rows %}
     <tbody>
-    {% for row in rows %}
-      <tr{{ row.attributes }}>
-      {% for cell in row.cells %}
-        {{ theme('table_cell', cell) }} {# no td here since this calls table_cell #}
+      {% for row in rows %}
+        <tr{{ row.attributes }}>
+        {%- for cell in row.cells -%}
+          {{ theme('table_cell', cell) }} {# Note: <td> returned by table_cell. #}
+        {%- endfor -%}
+        </tr>
       {% endfor %}
-      </tr>
-    {% endfor %}
     </tbody>
   {% endif %}
 </table>
