diff --git a/includes/common.inc b/includes/common.inc
index cbfdabb..a09d343 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -6345,7 +6345,7 @@ function drupal_array_set_nested_value(array &$array, array $parents, $value, $f
  *
  * @see drupal_array_set_nested_value()
  */
-function drupal_array_get_nested_value(array &$array, array $parents, &$key_exists = NULL) {
+function &drupal_array_get_nested_value(array &$array, array $parents, &$key_exists = NULL) {
   $ref = &$array;
   foreach ($parents as $parent) {
     if (is_array($ref) && array_key_exists($parent, $ref)) {
@@ -6353,7 +6353,8 @@ function drupal_array_get_nested_value(array &$array, array $parents, &$key_exis
     }
     else {
       $key_exists = FALSE;
-      return NULL;
+      $null = NULL;
+      return $null;
     }
   }
   $key_exists = TRUE;
diff --git a/includes/form.inc b/includes/form.inc
index df1b2f7..50d2759 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -2100,30 +2100,13 @@ function form_state_values_clean(&$form_state) {
   foreach ($form_state['buttons'] as $button) {
     // Remove this button's value from the submitted form values by finding
     // the value corresponding to this button.
-    // We iterate over the #parents of this button and move a reference to
-    // each parent in $form_state['values']. For example, if #parents is:
-    //   array('foo', 'bar', 'baz')
-    // then the corresponding $form_state['values'] part will look like this:
-    // array(
-    //   'foo' => array(
-    //     'bar' => array(
-    //       'baz' => 'button_value',
-    //     ),
-    //   ),
-    // )
-    // We start by (re)moving 'baz' to $last_parent, so we are able unset it
-    // at the end of the iteration. Initially, $values will contain a
-    // reference to $form_state['values'], but in the iteration we move the
-    // reference to $form_state['values']['foo'], and finally to
-    // $form_state['values']['foo']['bar'], which is the level where we can
-    // unset 'baz' (that is stored in $last_parent).
     $parents = $button['#parents'];
-    $values = &$form_state['values'];
     $last_parent = array_pop($parents);
-    foreach ($parents as $parent) {
-      $values = &$values[$parent];
+    $key_exists = NULL;
+    $values = &drupal_array_get_nested_value($form_state['values'], $parents, $key_exists);
+    if ($key_exists && is_array($values)) {
+      unset($values[$last_parent]);
     }
-    unset($values[$last_parent]);
   }
 }
 
