diff --git a/includes/ajax.inc b/includes/ajax.inc
index 05416af..ad8abdb 100644
--- a/includes/ajax.inc
+++ b/includes/ajax.inc
@@ -324,10 +324,11 @@ function ctools_ajax_command_css_files($argument) {
  * @param $argument
  *   An array of key: value pairs to add to the settings.
  */
-function ctools_ajax_command_settings($argument) {
+function ctools_ajax_command_settings($argument, $merge = FALSE) {
   return array(
     'command' => 'settings',
     'argument' => $argument,
+    'merge' => $merge,
   );
 }
 
@@ -453,7 +454,7 @@ function ctools_ajax_command_submit($selector) {
  * Render a commands array into JSON and immediately hand this back
  * to the AJAX requester.
  */
-function ctools_ajax_render($commands = array()) {
+function ctools_ajax_render($commands = array(), $return = FALSE, $merge = FALSE) {
   $js_files = array();
   $settings = ctools_process_js_files($js_files, 'header');
   $settings += ctools_process_js_files($js_files, 'footer');
@@ -503,7 +504,7 @@ function ctools_ajax_render($commands = array()) {
   }
 
   if (!empty($settings)) {
-    array_unshift($commands, ctools_ajax_command_settings(call_user_func_array('array_merge_recursive', $settings)));
+    array_unshift($commands, ctools_ajax_command_settings(call_user_func_array('array_merge_recursive', $settings), $merge));
   }
 
   if (!empty($_REQUEST['ctools_multipart'])) {
@@ -512,9 +513,12 @@ function ctools_ajax_render($commands = array()) {
     // as per the "file uploads" example here: http://malsup.com/jquery/form/#code-samples
     echo '<textarea>' . drupal_to_js($commands) . '</textarea>';
   }
-  else {
+  elseif (!$return) {
     drupal_json($commands);
   }
+  else {
+    return $commands;
+  }
   exit;
 }
 
diff --git a/js/ajax-responder.js b/js/ajax-responder.js
index 60ee17a..82a9b9a 100644
--- a/js/ajax-responder.js
+++ b/js/ajax-responder.js
@@ -443,7 +443,12 @@
   };
 
   Drupal.CTools.AJAX.commands.settings = function(data) {
-    $.extend(Drupal.settings, data.argument);
+    if (data.merge) {
+       $.extend(true, Drupal.settings, data.argument);
+    }
+    else {
+      $.extend(Drupal.settings, data.argument);
+    }
   };
 
   Drupal.CTools.AJAX.commands.scripts = function(data) {
