diff --git a/hierarchical_select.module b/hierarchical_select.module
index 6e23f04..d1fc712 100644
--- a/hierarchical_select.module
+++ b/hierarchical_select.module
@@ -327,7 +327,10 @@ function hierarchical_select_json() {
   // Collect all necessary variables.
   $cached = cache_get($hs_form_build_id, 'cache_hierarchical_select');
   $storage = $cached->data;
-
+  if (!$storage) {
+    $storage = $_SESSION['hierarchical_select_js'];
+  }
+  
   // Ensure that the form id in the POST array is the same as the one of the
   // stored parameters of the original form. For 99% of the forms, this step
   // is not necessary, but when a hierarchical_select form item is inside a
@@ -364,7 +367,7 @@ function hierarchical_select_json() {
   // Render only the relevant part of the form (i.e. the hierarchical_select
   // form item that has triggered this AJAX callback).
   $hsid = $_POST['hsid'];
-  $name = $storage['#names'][$hsid];
+  $name = $storage['#names'][key($storage['#names'])];
   $part_of_form = _hierarchical_select_get_form_item($form, $name);
   $output = drupal_render($part_of_form);
 
@@ -765,6 +768,7 @@ function hierarchical_select_after_build($form, &$form_state) {
     $hs_form_build_id = 'hs_form_'. md5(mt_rand());
     $lifetime = variable_get('hierarchical_select_cache_lifetime', HS_CACHE_LIFETIME_DEFAULT);
     cache_set($hs_form_build_id, $storage, 'cache_hierarchical_select', time() + $lifetime);
+    $_SESSION['hierarchical_select_js'] = $storage;
   }
   elseif (isset($_POST['hs_form_build_id'])) {
     // Don't generate a new hs_form_build_id if this is a re-rendering of the
