diff --git a/includes/webform.submissions.inc b/includes/webform.submissions.inc
index e3a656e..c714705 100644
--- a/includes/webform.submissions.inc
+++ b/includes/webform.submissions.inc
@@ -636,29 +636,47 @@ function webform_submission_render($node, $submission, $email, $format, $exclude
   $renderable['#theme'] = array('webform_submission_' . $node->nid, 'webform_submission');
 
   $components = $node->webform['components'];
-  
+
   // Remove excluded components.
   if (is_array($excluded_components)) {
     foreach ($excluded_components as $cid) {
       unset($components[$cid]);
     }
-    if ($email && $email['exclude_empty']) {
-      foreach ($submission->data as $cid => $data) {
-        // Caution. Grids store their data in an array index by question key.
-        foreach ($data as $value) {
+  }
+
+  module_load_include('inc', 'webform', 'includes/webform.components');
+  _webform_components_tree_build($components, $component_tree, 0, $page_count);
+
+  // Filter out the empty value components if exclude is turned on.
+  if ($email && $email['exclude_empty']) {
+    foreach ($node->webform['components'] as $cid => $component) {
+      $empty_values = true;
+      if ( isset($submission->data[$cid]) ) {
+        foreach ($submission->data[$cid] as $value) {
           if ($value != '') {
-            // This component has a non-empty value. Continue the outer loop.
-            continue 2;
+            // This component has a non-empty value.
+            $empty_values = false;
+          }
+        }
+      }
+      if ($empty_values) {
+        if (!isset($component_tree['children'][$cid]['children']) || empty($component_tree['children'][$cid]['children'])) {
+          unset($component_tree['children'][$cid]);
+          // Unset the same component when it's a child.
+          foreach($component_tree['children'] as $parent_cid => &$child_component){
+            if ( isset($child_component['children'][$cid]) ) {
+              unset($child_component['children'][$cid]);
+              // If we unset a child, we have to check it's empty after the unset (this specific component)
+              if (empty($child_component['children']) ) {
+                unset($component_tree['children'][$parent_cid]);
+              }
+            }
           }
         }
-        unset($components[$cid]);
       }
     }
   }
 
-  module_load_include('inc', 'webform', 'includes/webform.components');
-  _webform_components_tree_build($components, $component_tree, 0, $page_count);
-
   // Make sure at least one field is available
   if (isset($component_tree['children'])) {
     // Recursively add components to the form.
