359a360,362
>     $last_hsid = drupal_array_get_nested_value($form_state, array('storage', 'hs', 'last_hsid'));
>     if ($last_hsid <= $hsid)
>     	$form_state['storage']['hs']['last_hsid'] = $hsid;
690,697c693,705
< function form_hierarchical_select_process($element, &$form_state, $complete_form) {  
<   // dpm('#process');
<   // dpm($form_state);
<   //
<   // Calculations.
<   //
< 
<   // Determine the HSID.
---
> function form_hierarchical_select_process($element, &$form_state, $complete_form) {
> 	if(arg(0) != 'hierarchical_select_ajax') {  //@TODO: verify if we have AJAX call
> 		$cid = isset($element['#parents']) ? implode("-",$element['#parents']) : implode("-",$element['#field_parents']); //Get unique identifier using parents of the field
> 		$elhsid = drupal_array_get_nested_value($element, array('#value', 'hsid')); // verify if hsid is present or not
> 		if (!isset($elhsid)) {
> 			$cached = drupal_array_get_nested_value($form_state, array('storage', 'hs', 'hs_fields', $cid));	//retrieve previous element from form_state	
> 		}
> 		if (empty($cached))
> 			$docache = TRUE;
> 		else
> 			return $cached;  //switch courrent element with the "cached" one))
> 	}
> 	// Determine the HSID.
699c707,712
< 
---
> /**
>   if ($hsid == 0 && drupal_array_nested_key_exists($form_state, array('storage', 'hs', 'hs_fields'))) {
>   	unset($form_state['storage']['hs']['hs_fields']);
>   }
> **/
>   
715d727
< 
812c824,825
< 
---
>   if (!empty($docache))
>   	$form_state['storage']['hs']['hs_fields'][$cid] = $element;	//store new element in cache
