diff --git a/schema_metatag.module b/schema_metatag.module
index 693830b..00f4064 100644
--- a/schema_metatag.module
+++ b/schema_metatag.module
@@ -39,28 +39,10 @@ function schema_metatag_html_head_alter(&$elements) {
 function schema_metatag_element_validate($element, &$form_state, $form) {
   // For values that are not string values but instead nested arrays,
   // serialize the results into a single string value.
-  if ($value = schema_metatag_extract_value($element)) {
+  $keys = $element['#array_parents'];
+  $value = $form_state['values'][$keys[0]][$keys[1]][$keys[3]][$keys[4]];
+  if (is_array($value)) {
     $value = SchemaMetatagManager::serialize($value);
     form_set_value($element, $value, $form_state);
   }
 }
-
-/**
- * Recurse into $element to retrieve the whole array of values.
- */
-function schema_metatag_extract_value($element) {
-  $value = [];
-  $children = element_children($element);
-  if (is_array($element) && count($children) > 0) {
-    foreach ($children as $key) {
-      $children2 = element_children($element[$key]);
-      if (is_array($element[$key]) && count($children2) > 0) {
-        $value[$key] = schema_metatag_extract_value($element[$key]);
-      }
-      else {
-        $value[$key] = $element[$key]['#value'];
-      }
-    }
-  }
-  return $value;
-}
diff --git a/src/SchemaMetatagManager.php b/src/SchemaMetatagManager.php
index 4d3ab4f..fc7860d 100644
--- a/src/SchemaMetatagManager.php
+++ b/src/SchemaMetatagManager.php
@@ -148,7 +148,7 @@ class SchemaMetatagManager implements SchemaMetatagManagerInterface {
   }
 
   /**
-   * If the item is an array with numeric keys, count the keys.
+   * {@inheritdoc}
    */
   public static function countNumericKeys($item) {
     if (!is_array($item)) {
@@ -248,31 +248,24 @@ class SchemaMetatagManager implements SchemaMetatagManagerInterface {
     return FALSE;
   }
 
-  /**
-   * Not used, test to remove empty element from array.
-   */
-  public static function test($input) {
-    $iterator = new \RecursiveIteratorIterator(
-      new \RecursiveCallbackFilterIterator(
-        new \RecursiveArrayIterator($input),
-        function ($value) {
-          return trim($value) !== NULL && trim($value) !== '';
-        }
-      ), \RecursiveIteratorIterator::CHILD_FIRST
-    );
-    $result = $iterator->getArrayCopy();
-    return $result;
-  }
-
   /**
    * {@inheritdoc}
    */
-  public static function arrayTrim($input) {
-    return is_array($input) ? array_filter($input,
-      function (& $value) {
-        return $value = self::arrayTrim($value);
+  public static function arrayTrim($array) {
+    foreach ($array as $key => &$value) {
+      if (empty($value)) {
+        unset($array[$key]);
+      }
+      else {
+        if (is_array($value)) {
+          $value = static::arrayTrim($value);
+          if (empty($value)) {
+            unset($array[$key]);
+          }
+        }
       }
-    ) : $input;
+    }
+    return $array;
   }
 
   /**
@@ -286,13 +279,7 @@ class SchemaMetatagManager implements SchemaMetatagManagerInterface {
   }
 
   /**
-   * Generates a pseudo-random string of ASCII characters of codes 32 to 126.
-   *
-   * @param int $length
-   *   Length of random string to generate.
-   *
-   * @return string
-   *   Pseudo-randomly generated unique string including special characters.
+   * {@inheritdoc}
    */
   public static function randomString($length = 8) {
     $randomGenerator = new Random();
@@ -306,13 +293,7 @@ class SchemaMetatagManager implements SchemaMetatagManagerInterface {
   }
 
   /**
-   * Generates a unique random string containing letters and numbers.
-   *
-   * @param int $length
-   *   Length of random string to generate.
-   *
-   * @return string
-   *   Randomly generated unique string.
+   * {@inheritdoc}
    */
   public static function randomMachineName($length = 8) {
     $randomGenerator = new Random();
@@ -320,10 +301,7 @@ class SchemaMetatagManager implements SchemaMetatagManagerInterface {
   }
 
   /**
-   * Default values for input into nested base elements.
-   *
-   * @return array
-   *   An array of default values.
+   * {@inheritdoc}
    */
   public static function defaultInputValues() {
     return [
diff --git a/src/SchemaMetatagManagerInterface.php b/src/SchemaMetatagManagerInterface.php
index 858d3c9..232b9fb 100644
--- a/src/SchemaMetatagManagerInterface.php
+++ b/src/SchemaMetatagManagerInterface.php
@@ -49,6 +49,11 @@ interface SchemaMetatagManagerInterface {
    */
   public static function pivot($content);
 
+  /**
+   * If the item is an array with numeric keys, count the keys.
+   */
+  public static function countNumericKeys($item);
+
   /**
    * Explode values if this is a multiple value field.
    */
@@ -74,7 +79,7 @@ interface SchemaMetatagManagerInterface {
    *
    * If the result is an empty array, the nested array is completely empty.
    */
-  public static function arrayTrim($input);
+  public static function arrayTrim($array);
 
   /**
    * Update serialized item length computations.
@@ -84,4 +89,34 @@ interface SchemaMetatagManagerInterface {
    */
   public static function recomputeSerializedLength($value);
 
+  /**
+   * Generates a pseudo-random string of ASCII characters of codes 32 to 126.
+   *
+   * @param int $length
+   *   Length of random string to generate.
+   *
+   * @return string
+   *   Pseudo-randomly generated unique string including special characters.
+   */
+  public static function randomString($length = 8);
+
+  /**
+   * Generates a unique random string containing letters and numbers.
+   *
+   * @param int $length
+   *   Length of random string to generate.
+   *
+   * @return string
+   *   Randomly generated unique string.
+   */
+  public static function randomMachineName($length = 8);
+
+  /**
+   * Default values for input into nested base elements.
+   *
+   * @return array
+   *   An array of default values.
+   */
+  public static function defaultInputValues();
+
 }
