diff --git a/templates/bootstrap/bootstrap-panel.vars.php b/templates/bootstrap/bootstrap-panel.vars.php
index 685b67a..1e19686 100644
--- a/templates/bootstrap/bootstrap-panel.vars.php
+++ b/templates/bootstrap/bootstrap-panel.vars.php
@@ -9,11 +9,18 @@
  */
 function bootstrap_preprocess_bootstrap_panel(&$variables) {
   $element = &$variables['element'];
-  $attributes = !empty($element['#attributes']) ? $element['#attributes'] : array();
-  $attributes['class'][] = 'panel';
-  $attributes['class'][] = 'panel-default';
+
+  // Set the element's attributes.
+  element_set_attributes($element, array('id', 'name', 'value', 'type'));
+
+  // Add panel and panel-default classes.
+  $element['#attributes']['class'][] = 'panel';
+  $element['#attributes']['class'][] = 'panel-default';
+
   // states.js requires form-wrapper on fieldset to work properly.
-  $attributes['class'][] = 'form-wrapper';
+  $element['#attributes']['class'][] = 'form-wrapper';
+
+  // Handle collapsible panels.
   $variables['collapsible'] = FALSE;
   if (isset($element['#collapsible'])) {
     $variables['collapsible'] = $element['#collapsible'];
@@ -27,14 +34,18 @@ function bootstrap_preprocess_bootstrap_panel(&$variables) {
     $variables['collapsible'] = FALSE;
     $variables['collapsed'] = FALSE;
   }
-  if (!isset($element['#id']) && $variables['collapsible']) {
-    $element['#id'] = drupal_html_id('bootstrap-panel');
+  // Collapsible elements need an ID, so generate one if necessary.
+  if (!isset($element['#attributes']['id']) && $variables['collapsible']) {
+    $element['#attributes']['id'] = drupal_html_id('bootstrap-panel');
   }
+
+  // Set the target if the element has an id.
   $variables['target'] = NULL;
-  if (isset($element['#id'])) {
-    $attributes['id'] = $element['#id'];
-    $variables['target'] = '#' . $element['#id'] . ' > .collapse';
+  if (isset($element['#attributes']['id'])) {
+    $variables['target'] = '#' . $element['#attributes']['id'] . ' > .collapse';
   }
+
+  // Build the panel content.
   $variables['content'] = $element['#children'];
   if (isset($element['#value'])) {
     $variables['content'] .= $element['#value'];
@@ -50,12 +61,12 @@ function bootstrap_preprocess_bootstrap_panel(&$variables) {
   foreach ($keys as $key) {
     $variables[$key] = !empty($element["#$key"]) ? $element["#$key"] : FALSE;
   }
-  $variables['attributes'] = $attributes;
 }
 
 /**
  * Implements hook_process_bootstrap_panel().
  */
 function bootstrap_process_bootstrap_panel(&$variables) {
-  $variables['attributes'] = drupal_attributes($variables['attributes']);
+  $element = &$variables['element'];
+  $variables['attributes'] = drupal_attributes($element['#attributes']);
 }
