diff --git a/uc_attribute/uc_attribute.module b/uc_attribute/uc_attribute.module
index fd63d644..c63e7e0c 100644
--- a/uc_attribute/uc_attribute.module
+++ b/uc_attribute/uc_attribute.module
@@ -330,9 +330,10 @@ function uc_attribute_uc_form_alter(&$form, &$form_state, $form_id) {
         $element = &$form['sub_products'];
       }
       foreach (element_children($element) as $key) {
-        $element[$key]['attributes'] = _uc_attribute_alter_form($id . '-' . $key, $node->products[$key], $use_ajax);
+        $attributes_element = _uc_attribute_alter_form($id . '-' . $key, $node->products[$key], $use_ajax);
 
-        if (is_array($element[$key]['attributes'])) {
+        if (is_array($attributes_element)) {
+          $element[$key]['attributes'] = $attributes_element;
           $element[$key]['attributes']['#tree'] = TRUE;
           $element[$key]['#type'] = 'fieldset';
         }
@@ -340,9 +341,10 @@ function uc_attribute_uc_form_alter(&$form, &$form_state, $form_id) {
     }
     // If not, add attributes to the node.
     else {
-      $form['attributes'] = _uc_attribute_alter_form($id, $node, $use_ajax);
+      $attributes_element = _uc_attribute_alter_form($id, $node, $use_ajax);
 
-      if (is_array($form['attributes'])) {
+      if (is_array($attributes_element)) {
+        $form['attributes'] = $attributes_element;
         $form['attributes']['#tree'] = TRUE;
         $form['attributes']['#weight'] = -1;
       }
