--- uc_signup.module.OLD	2010-08-22 02:03:19.000000000 +1000
+++ uc_signup.module	2010-09-16 01:13:55.000000000 +1000
@@ -93,7 +93,6 @@
   // $form now has a fieldset for each profile field category.
   // We want an array of individual field elements from the first category.
   $form = array_values($form);
-  $form = $form[0];
   foreach (element_children($form) as $key => $val) {
     $new_form[$val] = $form[$val];
   }
@@ -265,7 +264,6 @@
     }
   }
 
-  $profile_form = uc_signup_profile_form();
   $mail = '';
   foreach ($mails as $mail => $events) {
     $form[$mail] = array(
@@ -286,16 +284,19 @@
       $profile_form = uc_signup_profile_form();
       if (!empty($profile_form)) {
         $form[$mail]['profile'] = $profile_form;
-        foreach ($form[$mail]['profile'] as $key => $value) {
+        foreach ($form[$mail]['profile'] as $group => $fields) {
+          foreach ($fields as $key => $value) {
           $default = $form_state['values']['profile'][$key .'_'. $mail];
           if (empty($default)) {
             $default = $_SESSION['uc_signup']['profile'][$key .'_'. $mail];
           }
           if ($key[0] != '#') {
-            $form[$mail]['profile'][$key .'_'. $mail] = $value;
-            unset($form[$mail]['profile'][$key]);
-            $form[$mail]['profile'][$key .'_'. $mail]['#default_value'] = $default;
-            $form[$mail]['profile']['#tree'] = TRUE;
+              $form[$mail]['profile'][$group][$key .'_'. $mail] = $value;
+              unset($form[$mail]['profile'][$group][$key]);
+              $form[$mail]['profile'][$group][$key .'_'. $mail]['#default_value'] = $default;
+              $form[$mail]['profile'][$group][$key .'_'. $mail]['#parents'] = array('profile', $key .'_'. $mail);
+            }
+          }
           }
           drupal_add_css(drupal_get_path('module', 'uc_signup') .'/uc_signup.css');
           $form[$mail]['has_account'] = array(
@@ -305,7 +306,6 @@
           );
         }
       }
-    }
     else {
       drupal_add_css(drupal_get_path('module', 'uc_signup') .'/uc_signup.css');
       $form[$mail]['has_account'] = array(
@@ -663,9 +663,11 @@
               $form_state['values']['pass'] =  user_password(8);
               $form_state['values']['notify'] = (bool)variable_get('uc_signup_account_notify', 1);
               $profile_form =  uc_signup_profile_form();
-              foreach ($profile_form as $key => $value) {
+              foreach ($profile_form as $group => $fields) {
+                foreach ($fields as $key => $value) {
                 $form_state['values'][$key] = $_SESSION['uc_signup']['profile'][$key .'_'. $mail];
               }
+              }
               
               //We masquerade as user 1 in case there is captcha or other protection on the user_register form that could cause submission to fail.
               global $user;
