diff --git a/imagefield_zip.ahah.inc b/imagefield_zip.ahah.inc
index c69ec6f..7c52533 100644
--- a/imagefield_zip.ahah.inc
+++ b/imagefield_zip.ahah.inc
@@ -36,8 +36,17 @@ function imagefield_zip_js($type_name, $field_name) {
   // Generate HTML for the images that where uploaded
   $result = imagefield_zip_add_files_to_form($type_name, $field_name, $images);
 
+  // Destory the orginal zip upload form and replace it with the clean clone.
+  $id = 'edit-' . str_replace('_', '-', $field_name) . '-upload';
+  $extra_js .= '<script type="text/javascript">
+  _imagefield_zip_' . $field_name . '_cloned.insertAfter(_imagefield_zip_' . $field_name . '_real);
+  _imagefield_zip_' . $field_name . '_real.remove();
+  _imagefield_zip_' . $field_name . '_real = $("#' . $id . '");
+  _imagefield_zip_' . $field_name . '_cloned = _imagefield_zip_' . $field_name . '_real.clone(true);
+  </script>';
+
   // Theme HTML
-  $data = theme('status_messages') . $result;
+  $data = theme('status_messages') . $result . $extra_js;
   if ($result !== FALSE) {
     $return = array('data' => $data, 'status' => TRUE);
   }
@@ -155,6 +164,7 @@ function imagefield_zip_add_files_to_form($type_name, $field_name, $files) {
       $form_element[$field_name][$delta] = $delta_element;
     }
   }
+  $form_element['#id'] = 'imagefield_zip_js';
 
   // Let other modules alter it.
   // We pass an empty array as hook_form_alter's usual 'form_state' parameter,
@@ -164,7 +174,7 @@ function imagefield_zip_add_files_to_form($type_name, $field_name, $files) {
   $data = &$form_element;
   $empty_form_state = array();
   $data['__drupal_alter_by_ref'] = array(&$empty_form_state);
-  drupal_alter('form', $data, 'content_add_more_js');
+  drupal_alter('form', $data, 'imagefield_zip_js');
 
   // Add the new element at the right place in the (original, unbuilt) form.
   $success = content_set_nested_elements($form, $field_name, $form_element[$field_name]);
@@ -193,6 +203,7 @@ function imagefield_zip_add_files_to_form($type_name, $field_name, $files) {
   // Prevent duplicate wrapper.
   unset($field_form['#prefix'], $field_form['#suffix']);
 
+  // Generate the new html.
   $output = drupal_render($field_form);
 
   // If a newly inserted widget contains AHAH behaviors, they normally won't
@@ -203,15 +214,6 @@ function imagefield_zip_add_files_to_form($type_name, $field_name, $files) {
   $javascript = drupal_add_js(NULL, NULL);
   $output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>' : '';
 
-  // Destory the orginal zip upload form and replace it with the clean clone.
-  $id = 'edit-' . str_replace('_', '-', $field_name) . '-upload';
-  $output_js .= '<script type="text/javascript">
-  _imagefield_zip_' . $field_name . '_cloned.insertAfter(_imagefield_zip_' . $field_name . '_real);
-  _imagefield_zip_' . $field_name . '_real.remove();
-  _imagefield_zip_' . $field_name . '_real = $("#' . $id . '");
-  _imagefield_zip_' . $field_name . '_cloned = _imagefield_zip_' . $field_name . '_real.clone(true);
-  </script>';
-
   // Using drupal_json() breaks filefield's file upload, because the jQuery
   // Form plugin handles file uploads in a way that is not compatible with
   // 'text/javascript' response type.
