Why is my form_state being reset after submission? I have a menu item with page callback:

function my_menu() {
  $items = array();
  $items['my/action/%ctools_js'] = array(
    'title' =&gt; 'do something',
    'page callback' =&gt; 'my_action',
    'page arguments' =&gt; array(2,3),
    'access callback' =&gt; TRUE,
    'type' =&gt; MENU_CALLBACK,
  );
}

function my_action($js = NULL, $nid = NULL) {
  $form_state = array('nid' =&gt; $nid);
  if(!$js) {
    drupal_build_form('my_action_form', $form_state);
  }
  ctools_include('modal');
  ctools_include('ajax');
  $form_state['ajax'] = $js;
  $form_state['title'] = t('Form Title');
  $output = drupal_build_form('my_action_form', $form_state);
  $commands = array();
  if (!empty($form_state['finished'])) {
    $commands[] = ctools_modal_command_dismiss();
    $commands[] = ctools_ajax_command_redirect('challenges');
  } else {
    ctools_modal_form_render($form_state, $output);
  }
  print ajax_render($commands);
  exit;
}

function my_action_form($form, &amp;$form_state) {
  // form fields defined here
}

function my_action_form_validate($form, &amp;$form_state) {
  // $form_state['finished'] = true;
}

function my_action_form_submit($form, &amp;$form_state) {
  $form_state['finished'] = true;
}


If I uncomment out the line in my_action_form_validate The modal form dismisses and the redirect works. But with that line commented out when I try to set the $form_state var in submit, the modal doesn't dismiss and doesn't redirect. The form submit code executes (calls to drupal_set_message work fine), but by the time it gets back to the conditional (line 11) in my_action, $form_state has been set to default and a blank form reappears in the modal popup. How can I dismiss the modal window after submission?
The issue was in the callback frunction my_action(). I was using the ctools_modal_form_render() function wrong. In the end I replaced the call to ctools_modal_form_render() with ctools_modal_form_wrapper():

function my_action($js = NULL, $nid = NULL) {
  if(!$js) {
    $form_state = array( 'nid' =&gt; $nid );
    return drupal_build_form('my_action_form', $form_state);
  }
  ctools_include('modal');
  ctools_include('ajax');
  $form_state = array(
    'title' =&gt; t('My Action Form'),
    'ajax' =&gt; TRUE,
    'nid' =&gt; $nid
  );
  $output = ctools_modal_form_wrapper('my_action_form', $form_state);
  if ( !empty($form_state['executed']) ) {
    $output = array();
    $output[] = ctools_modal_command_dismiss();
  }
  print ajax_render($output);
  exit;
}