diff --git a/conditional_fields.module b/conditional_fields.module
index 27ea7ee..37f7b2f 100644
--- a/conditional_fields.module
+++ b/conditional_fields.module
@@ -259,11 +259,13 @@ function conditional_fields_element_after_build($element, &$form_state) {
     return $element;
   }
 
+  $field_parents_key = conditional_fields_flatten_array($field['#field_parents']);
+
   // Attach dependent.
   if (isset($dependencies['dependents'][$field['#field_name']])) {
     foreach ($dependencies['dependents'][$field['#field_name']] as $id => $dependency) {
-      if (!isset($form['#conditional_fields'][$field['#field_name']]['dependees'][$id])) {
-        conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $id);
+      if (!isset($form['#conditional_fields'][$field_parents_key][$field['#field_name']]['dependees'][$id])) {
+        conditional_fields_attach_dependency($form, array('#field_name' => $dependency['dependee']), $field, $dependency['options'], $field_parents_key, $id);
       }
     }
   }
@@ -274,8 +276,8 @@ function conditional_fields_element_after_build($element, &$form_state) {
   // define per-element sets of dependency values.
   if (isset($dependencies['dependees'][$field['#field_name']])) {
     foreach ($dependencies['dependees'][$field['#field_name']] as $id => $dependency) {
-      if (!isset($form['#conditional_fields'][$field['#field_name']]['dependents'][$id])) {
-        conditional_fields_attach_dependency($form, $field, array('#field_name' => $dependency['dependent']), $dependency['options'], $id);
+      if (!isset($form['#conditional_fields'][$field_parents_key][$field['#field_name']]['dependents'][$id])) {
+        conditional_fields_attach_dependency($form, $field, array('#field_name' => $dependency['dependent']), $dependency['options'], $field_parents_key, $id);
       }
     }
   }
@@ -353,7 +355,7 @@ function conditional_fields_element_after_build($element, &$form_state) {
  *   Note that you don't need to manually set all these options, since default
  *   settings are always provided.
  */
-function conditional_fields_attach_dependency(&$form, $dependee, $dependent, $options, $id = 0) {
+function conditional_fields_attach_dependency(&$form, $dependee, $dependent, $options, $field_parents_key, $id = 0) {
   $options += conditional_fields_dependency_default_options();
 
   // The absence of the $id parameter identifies a custom dependency.
@@ -384,8 +386,8 @@ function conditional_fields_attach_dependency(&$form, $dependee, $dependent, $op
   // Use the #parents property of the dependee instead of #field_parents since
   // we will need access to the full structure of the widget.
   if (isset($dependee['#parents'])) {
-    $form['#conditional_fields'][$dependee['#field_name']]['parents'] = $dependee['#parents'];
-    $form['#conditional_fields'][$dependee['#field_name']]['dependents'][$id] = array(
+    $form['#conditional_fields'][$field_parents_key][$dependee['#field_name']]['parents'] = $dependee['#parents'];
+    $form['#conditional_fields'][$field_parents_key][$dependee['#field_name']]['dependents'][$id] = array(
       'dependent' => $dependent['#field_name'],
       'options'   => $options,
     );
@@ -399,8 +401,8 @@ function conditional_fields_attach_dependency(&$form, $dependee, $dependent, $op
     $dependent_parents = $dependent['#parents'];
   }
   if (isset($dependent_parents)) {
-    $form['#conditional_fields'][$dependent['#field_name']]['field_parents'] = $dependent_parents;
-    $form['#conditional_fields'][$dependent['#field_name']]['dependees'][$id] = array(
+    $form['#conditional_fields'][$field_parents_key][$dependent['#field_name']]['field_parents'] = $dependent_parents;
+    $form['#conditional_fields'][$field_parents_key][$dependent['#field_name']]['dependees'][$id] = array(
       'dependee' => $dependee['#field_name'],
       'options'  => $options,
     );
@@ -428,13 +430,13 @@ function conditional_fields_form_after_build($form, &$form_state) {
   $state_handlers = conditional_fields_states_handlers();
 
   // Cycle all dependents.
-  foreach ($form['#conditional_fields'] as $dependent => $dependent_info) {
+  foreach ($form['#conditional_fields'] as $parent_dependent_key => $parent_dependent_info) {
+    foreach ($parent_dependent_info as $dependent => $dependent_info) {
       $states = array();
 
       if (empty($dependent_info['dependees'])) {
         continue;
       }
-
       $dependent_location = array_merge($dependent_info['field_parents'], array($dependent));
       $dependent_form_field = drupal_array_get_nested_value($form, $dependent_location);
 
@@ -442,11 +444,11 @@ function conditional_fields_form_after_build($form, &$form_state) {
       foreach ($dependent_info['dependees'] as $dependency) {
         $dependee = $dependency['dependee'];
 
-      if (empty($form['#conditional_fields'][$dependee])) {
+        if (empty($form['#conditional_fields'][$parent_dependent_key][$dependee])) {
           continue;
         }
 
-      $dependee_info = $form['#conditional_fields'][$dependee];
+        $dependee_info = $form['#conditional_fields'][$parent_dependent_key][$dependee];
         $dependee_form_field = drupal_array_get_nested_value($form, $dependee_info['parents']);
         $options = $dependency['options'];
 
@@ -477,7 +479,6 @@ function conditional_fields_form_after_build($form, &$form_state) {
           unset($behaviors[CONDITIONAL_FIELDS_FIELD_EDIT_HIDE_ORPHAN]);
           continue;
         }
-
         unset($behaviors[CONDITIONAL_FIELDS_FIELD_EDIT_HIDE_UNTRIGGERED_ORPHAN]);
         unset($behaviors[CONDITIONAL_FIELDS_FIELD_EDIT_HIDE_ORPHAN]);
 
@@ -527,6 +528,7 @@ function conditional_fields_form_after_build($form, &$form_state) {
           $state = array($options['state'] => array($options['selector'] => $values));
           $dependee_form_state = isset($dependee_form_field['#field_parents'], $dependee_form_field['#field_name'], $dependee_form_field['#language']) ? field_form_get_state($dependee_form_field['#field_parents'], $dependee_form_field['#field_name'], $dependee_form_field['#language'], $form_state) : NULL;
 
+
           // Execute special handler for fields that need further processing.
           // The handler has no return value. Modify the $state parameter by
           // reference if needed.
@@ -535,10 +537,10 @@ function conditional_fields_form_after_build($form, &$form_state) {
               $handler($dependee_form_field, $dependee_form_state, $options, $state);
             }
           }
+        }
 
         // Add validation callback to element.
         _conditional_fields_element_add_property($dependent_form_field, '#element_validate', 'conditional_fields_dependent_validate', 'append');
-      }
 
         // Add the $state into the correct logic group in $states.
         foreach ($state as $key => $constraints) {
@@ -549,6 +551,7 @@ function conditional_fields_form_after_build($form, &$form_state) {
             $states[$key][$options['grouping']] = array_merge($states[$key][$options['grouping']], $constraints);
           }
         }
+      }
 
         // Build effect settings for effects with options.
         // TODO: add dependee key to allow different effects on the same selector.
@@ -565,24 +568,12 @@ function conditional_fields_form_after_build($form, &$form_state) {
             'options' => $options['effect_options'],
           );
           }
-
         // Apply reset dependent to default if untriggered behavior.
         if (in_array(CONDITIONAL_FIELDS_FIELD_EDIT_RESET_UNTRIGGERED, $behaviors)) {
           // Add property to element so conditional_fields_dependent_validate() can
           // pick it up.
           $dependent_form_field['#conditional_fields_reset_if_untriggered'] = TRUE;
-        unset($behaviors[CONDITIONAL_FIELDS_FIELD_EDIT_RESET_UNTRIGGERED]);
-      }
-    }
-
-    // Execute custom behaviors callbacks.
-    if (!empty($behaviors)) {
-      foreach ($behaviors as $behavior) {
-        $behavior($form, $form_state, $dependent, $dependent_info);
-      }      
-    }
-
-    unset($behaviors);
+          unset($behaviors[CONDITIONAL_FIELDS_FIELD_EDIT_RESET_UNTRIGGERED]);      }
 
       if (empty($states)) {
         continue;
@@ -626,6 +617,7 @@ function conditional_fields_form_after_build($form, &$form_state) {
 
       $has_states = TRUE;
     }
+  }
 
   if (empty($has_states)) {
     return $form;
@@ -994,13 +986,14 @@ function conditional_fields_evaluate_grouping($groups) {
  *   The field form element in the current language.
  */
 function conditional_fields_evaluate_dependencies($dependent, $form, $form_state) {
-  $dependencies = $form['#conditional_fields'][$dependent['#field_name']]['dependees'];
+  $dependent_field_key = conditional_fields_flatten_array($dependent['#field_parents']);
+  $dependencies = $form['#conditional_fields'][$dependent_field_key][$dependent['#field_name']]['dependees'];
   $evaluated_dependees = array();
 
   foreach ($dependencies as $dependency_id => $dependency) {
     // Extract field values from submitted values.
     $dependee = $dependency['dependee'];
-    $dependee_parents = $form['#conditional_fields'][$dependee]['parents'];
+    $dependee_parents = $form['#conditional_fields'][$dependent_field_key][$dependee]['parents'];
 
     // We have the parents of the field, but depending on the entity type and
     // the widget type, they may include additional elements that are actually
@@ -1982,3 +1975,20 @@ function conditional_fields_features_api() {
     ),
   );
 }
+
+
+/**
+ * Flatten a one-dimensional array.
+ */
+function conditional_fields_flatten_array($array, $delta = 0, $separator = ':') {
+  $array_string = 'root'.$separator;
+  $array_count  = count($array);
+  foreach ($array as $array_value) {
+    $array_string .= $array_value;
+      if ($delta != $array_count) {
+        $array_string .= $separator;
+      }
+    $delta++;
+  }
+  return $array_string;
+}
