 
     %{ "groups" => config_groups } = Core.CategoryTreeList.find_by_name(doc["resource"]["type"], configuration)
     doc = put_in(doc, ["resource", "groups"], [])
-    doc = Enum.reduce(config_groups, doc,
-      fn config_group, doc ->
-        object_group = scan_group config_group, doc
-        update_in(doc, ["resource", "groups"], append(object_group))
-      end
-    )
 
+    groups = scan_and_add(&scan_group/2, config_groups, doc)
+    doc = put_in(doc, ["resource", "groups"], groups)
     update_in(doc, ["resource"], &(Map.take(&1, @core_fields)))
   end
 

    end
  end

  defp append(nil), do: fn list -> list end
  defp append(item), do: fn list -> list ++ [item] end
end

      "relations" => config_group_relations
    } = config_group

    fields = scan_and_add(&scan_field/2, config_group_fields, doc)
    relations = scan_and_add(&scan_relation/2, config_group_relations, doc)

    if length(fields) == 0 and length(relations) == 0 do
      nil
