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..9c50743 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)) {
 
@@ -2170,7 +2170,11 @@ function template_preprocess_table(&$variables) {
   $is_responsive = $variables['responsive'];
 
   // Table Child Elements
-  $headers = $variables['header'];
+  // Headers needed for reference of active sorting
+  // header after it's cells are processed
+  // array_values indexes for the table sort to work
+  $headers = array_values($variables['header']);
+  $variables['header'] = array();
   $rows = $variables['rows'];
   $colgroups = $variables['colgroups'];
 
@@ -2200,8 +2204,8 @@ function template_preprocess_table(&$variables) {
   // Format the table columns:
   if (!empty($colgroups)) {
     $variables['colgroups'] = array();
-    foreach ($colgroups as $number => $colgroup) {
-      $variables['colgroups'][$number] = array();
+    foreach ($colgroups as $colgroup_key => $colgroup) {
+      $variables['colgroups'][$colgroup_key] = array();
       $colgroup_attributes = array();
 
       // Check if we're dealing with a simple or complex colgroup
@@ -2220,14 +2224,14 @@ function template_preprocess_table(&$variables) {
       }
 
       // Build colgroup
-      $variables['colgroups'][$number]['attributes'] = new Attribute($colgroup_attributes);
+      $variables['colgroups'][$colgroup_key]['attributes'] = new Attribute($colgroup_attributes);
 
       // Build cols within colgroup
       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;
         }
       }
     }
@@ -2259,7 +2263,12 @@ function template_preprocess_table(&$variables) {
     $ts = tablesort_init($headers);
     $i = 0;
     foreach ($headers as $key => $cell) {
-      $i++;
+
+      // If the cell is not an array, make it one
+      if (!is_array($cell)) {
+        $cell = array('data' => $cell);
+      }
+
       // 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
@@ -2271,22 +2280,18 @@ function template_preprocess_table(&$variables) {
         elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) {
           $responsive_classes[$i] = RESPONSIVE_PRIORITY_LOW;
         }
-      }
 
-      // If the cell is not an array, make it one
-      if (!is_array($cell)) {
-        $cell = array('data' => $cell);
+        // Add classes to attributes
+        $cell['attributes']['class'] = $cell['class'];
+        unset($cell['class']);
       }
 
       $cell = tablesort_header($cell, $headers, $ts);
 
       // Tell the cell to be a header
       $cell['header'] = TRUE;
-
-      // Convert to the format table_cell preprocesser will accept
-      $cell = array('cell' => $cell);
-
-      $headers[$key] = $cell;
+      $variables['header'][$i] = $cell;
+      $i++;
     }
   }
   else {
@@ -2303,7 +2308,7 @@ function template_preprocess_table(&$variables) {
     );
     $class = 'even';
 
-    foreach ($rows as $number => $row) {
+    foreach ($rows as $row_key => $row) {
 
       $row_attributes = array();
       $cells = array();
@@ -2332,13 +2337,11 @@ function template_preprocess_table(&$variables) {
 
       if (!empty($cells)) {
         // Build row
-        $variables['rows'][$number] = array();
-        $variables['rows'][$number]['attributes'] = new Attribute($row_attributes);
-        $variables['rows'][$number]['cells'] = array();
+        $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 (!is_array($cell)) {
             $cell = array('data' => $cell);
@@ -2350,14 +2353,12 @@ function template_preprocess_table(&$variables) {
           // 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;
+          $variables['rows'][$row_key]['cells'][$i] = $cell;
+          $i++;
         }
       }
     }
@@ -2366,9 +2367,6 @@ function template_preprocess_table(&$variables) {
   // Set the table attributes
   $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']);
@@ -2399,19 +2397,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 +2776,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 +2798,37 @@ 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 +3416,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()),
