diff --git includes/ajax.inc includes/ajax.inc
index 396514a..04b7091 100644
--- includes/ajax.inc
+++ includes/ajax.inc
@@ -270,7 +270,7 @@ function ajax_form_callback() {
 
   // This call recreates the form relying solely on the $form_state that
   // drupal_process_form() set up.
-  $form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
+  $form = ajax_rebuild_form($form_id, $form_state, $form);
 
   // As part of drupal_process_form(), the element that triggered the form
   // submission is determined, and in the case of AJAX, it might not be a
@@ -522,6 +522,61 @@ function ajax_process_form($element, &$form_state) {
 }
 
 /**
+ * Retrieves a form and caches it under the same build id.
+ *
+ * If your AJAX callback simulates the pressing of a button, then your AJAX
+ * callback will need to do the same as what drupal_get_form() would do when the
+ * button is pressed: get the form from the cache, run drupal_process_form over
+ * it and then if it needs rebuild, run ajax_rebuild_form over it. Then send
+ * back a part of the returned form.
+ * $form_state['trigger_element']['#array_parents'] will help you to find which
+ * part.
+ *
+ * @param $form_id
+ *   The unique string identifying the desired form.
+ * @param $form_state
+ *   A keyed array containing the current state of the form.
+ * @param $previous_form
+ *   The previous build of this form which is used to keep the properties of the
+ *   newly built form consistent with the prior build.
+ *
+ * @return
+ *   The newly built form.
+ */
+ function ajax_rebuild_form($form_id, &$form_state, $previous_form) {
+  // _form_builder_handle_input_element() needs to distinguish a
+  // rebuild from an initial build in order to process user input correctly.
+  // Form constructors and form processing functions may also need to handle a
+  // rebuild differently than an initial build.
+  $form_state['rebuild'] = TRUE;
+
+  $form = drupal_retrieve_form($form_id, $form_state);
+
+  // Use the same build_id as the previous form.
+  $form['#build_id'] = $previous_form['#build_id'];
+  drupal_prepare_form($form_id, $form, $form_state);
+
+  // Set the form's action to the old form's action so it doesn't get overridden
+  // by the form_builder().
+  $form['#action'] = $previous_form['#action'];
+
+  if (empty($form_state['no_cache'])) {
+    // We cache the form structure and the form state so it can be retrieved
+    // later for validation.
+    form_set_cache($previous_form['#build_id'], $form, $form_state);
+  }
+
+  // Clear out all group associations as these might be different when
+  // re-rendering the form.
+  $form_state['groups'] = array();
+
+  // Do not call drupal_process_form(), as that would validate and submit the
+  // form.
+  $form = form_builder($form_id, $form, $form_state);
+  return $form;
+}
+
+/**
  * @} End of "defgroup ajax".
  */
 
diff --git includes/form.inc includes/form.inc
index c2df0de..bf6d476 100644
--- includes/form.inc
+++ includes/form.inc
@@ -288,15 +288,6 @@ function form_state_defaults() {
 /**
  * Retrieves a form, caches it and processes it again.
  *
- * If your AJAX callback simulates the pressing of a button, then your AJAX
- * callback will need to do the same as what drupal_get_form() would do when the
- * button is pressed: get the form from the cache, run drupal_process_form over
- * it and then if it needs rebuild, run drupal_rebuild_form() over it. Then send
- * back a part of the returned form.
- * $form_state['triggering_element']['#array_parents'] will help you to find
- * which part.
- * @see ajax_form_callback() for an example.
- *
  * @param $form_id
  *   The unique string identifying the desired form. If a function
  *   with that name exists, it is called to build the form array.
@@ -306,34 +297,25 @@ function form_state_defaults() {
  *   may be found in node_forms(), search_forms(), and user_forms().
  * @param $form_state
  *   A keyed array containing the current state of the form.
- * @param $form_build_id
- *   If the AHAH callback calling this function only alters part of the form,
- *   then pass in the existing form_build_id so we can re-cache with the same
- *   csid.
  * @return
  *   The newly built form.
  */
-function drupal_rebuild_form($form_id, &$form_state, $form_build_id = NULL) {
-  // AJAX and other contexts may call drupal_rebuild_form() even when
-  // $form_state['rebuild'] isn't set, but _form_builder_handle_input_element()
-  // needs to distinguish a rebuild from an initial build in order to process
-  // user input correctly. Form constructors and form processing functions may
-  // also need to handle a rebuild differently than an initial build.
+function drupal_rebuild_form($form_id, &$form_state) {
+  // _form_builder_handle_input_element() needs to distinguish a
+  // rebuild from an initial build in order to process user input correctly.
+  // Form constructors and form processing functions may also need to handle a
+  // rebuild differently than an initial build.
   $form_state['rebuild'] = TRUE;
 
   $form = drupal_retrieve_form($form_id, $form_state);
 
-  if (!isset($form_build_id)) {
-    // We need a new build_id for the new version of the form.
-    $form_build_id = 'form-' . md5(mt_rand());
-  }
-  $form['#build_id'] = $form_build_id;
+  $form['#build_id'] = 'form-' . md5(mt_rand());
   drupal_prepare_form($form_id, $form, $form_state);
 
   if (empty($form_state['no_cache'])) {
     // We cache the form structure and the form state so it can be retrieved
     // later for validation.
-    form_set_cache($form_build_id, $form, $form_state);
+    form_set_cache($form['#build_id'], $form, $form_state);
   }
 
   // Clear out all group associations as these might be different when
diff --git modules/file/file.module modules/file/file.module
index 75f6973..7a3ee76 100644
--- modules/file/file.module
+++ modules/file/file.module
@@ -239,7 +239,7 @@ function file_ajax_upload() {
 
   // This call recreates the form relying solely on the form_state that the
   // drupal_process_form() set up.
-  $form = drupal_rebuild_form($form_id, $form_state, $form_build_id);
+  $form = ajax_rebuild_form($form_id, $form_state, $form_build_id, $form);
 
   // Retrieve the element to be rendered.
   foreach ($form_parents as $parent) {
