diff --git a/og_subgroups.common.inc b/og_subgroups.common.inc
index f228eed..b4bb048 100644
--- a/og_subgroups.common.inc
+++ b/og_subgroups.common.inc
@@ -374,7 +374,10 @@ function _og_subgroup_get_user_inherited_groups($account) {
  *
  * @see: _og_subgroup_get_user_inherited_groups().
  */
-function _og_subgroups_get_children_groups($group_type, $group_id, &$children_groups) {
+function _og_subgroups_get_children_groups($group_type, $group_id, &$children_groups, $count = 0) {
+  if ($count > 50) {
+    return FALSE;
+  }
   $children = og_subgroups_get_associated_entities($group_type, $group_id);
   foreach ($children as $children_type => $children_ids) {
     $children_entities = entity_load($children_type, $children_ids);
@@ -382,9 +385,14 @@ function _og_subgroups_get_children_groups($group_type, $group_id, &$children_gr
       if (og_is_group($children_type, $child_entity)) {
         $children_groups[$children_type][$child_id] = $child_entity;
         if (isset($child_entity->{OG_USER_INHERITANCE_FIELD}[LANGUAGE_NONE][0]['value']) && $child_entity->{OG_USER_INHERITANCE_FIELD}[LANGUAGE_NONE][0]['value']) {
-          _og_subgroups_get_children_groups($children_type, $child_id, $children_groups);
+          $result = _og_subgroups_get_children_groups($children_type, $child_id, $children_groups, $count + 1);
+          if (!$result && ($count == 0)) {
+            drupal_set_message(t('Bad child %child of group %nid ', array(
+              '%child' => $child_id, '%nid' => $group_id)), 'error');
+          }
         }
       }
     }
   }
+  return TRUE;
 }
\ No newline at end of file
