diff --git a/modalframe.module b/modalframe.module
index b854385..dd6e587 100644
--- a/modalframe.module
+++ b/modalframe.module
@@ -201,11 +201,63 @@ function modalframe_form_after_build_recursive(&$elements, &$form_state) {
  */
 function modalframe_form_submit($form, &$form_state) {
   if (!empty($GLOBALS['modalframe_close_dialog'])) {
-    $form_state['redirect'] = FALSE;
+    if ($batch = & batch_get()) {
+      $form_state['redirect'] = 'modalframe-close';
+      $_SESSION['modalframe_close_dialog_args'] = $GLOBALS['modalframe_close_dialog_args'];
+      $batch['url'] = 'modalframe-batch';
+    }
+    else {
+      $form_state['redirect'] = FALSE;
+    }
   }
 }
 
 /**
+ * Implementation of hook_menu().
+ */
+function modalframe_menu() {
+  $items = array();
+
+  $items['modalframe-close'] = array(
+    'title' => t('Close Frame'),
+    'description' => t('This is used purely internally to close a dialogue after batch finishes.'),
+    'page callback' => 'modalframe_batch_close',
+    'type' => MENU_CALLBACK,
+    'access callback' => TRUE
+  );
+
+  $items['modalframe-batch'] = array(
+    'page callback' => 'modalframe_system_batch_page', 
+    'access callback' => TRUE, 
+    'type' => MENU_CALLBACK, 
+    'file' => 'system.admin.inc',
+    'file path' => drupal_get_path('module', 'system'),
+  );
+
+
+  return $items;
+}
+
+/**
+ * Calls the batch page as a modalframe mimimal page.
+ */
+function modalframe_system_batch_page() {
+  modalframe_child_js();
+  return system_batch_page();
+}
+
+/**
+ * Closes modalframe after batch is done.
+ */
+function modalframe_batch_close() {
+  $args = isset($_SESSION['modalframe_close_dialog_args']) ? $_SESSION['modalframe_close_dialog_args'] : array();
+  unset($_SESSION['modalframe_close_dialog_args']);
+  modalframe_child_js();
+  modalframe_close_dialog($args);
+  return '';
+}
+
+/**
  * API: Add javascript and stylesheets to the parent page.
  *
  * @ingroup modalframe_api
@@ -288,4 +340,5 @@ function modalframe_close_dialog($args = NULL) {
   // so we do not wish to perform redirections after submitted form has been
   // processed.
   $GLOBALS['modalframe_close_dialog'] = TRUE;
+  $GLOBALS['modalframe_close_dialog_args'] = $args; 
 }
