public static NodeGroupGraph GroupNodes(List <Node> nodesToGroup, NodeGraph g, string name = "Nodes Group")
        {
            if (nodesToGroup.Count < 2)
            {
                Debug.LogWarning("Should be 2 or more nodes to make a group");
                return(null);
            }

            for (int i = nodesToGroup.Count - 1; i >= 0; i--)
            {
                Node node = nodesToGroup[i];
                if (node == null)
                {
                    Debug.LogError("Something went wrong!");
                    return(null);
                }

                if ((node is IVariableNode))
                {
                    nodesToGroup.Remove(node);
                    Debug.LogWarning("Removed GET/SET");
                }
                else
                {
                    node.name = node.name + "_" + node.GetHashCode();
                }
            }

            NodeGraph      gcopy          = g.Copy();
            NodeGroupGraph nodeGroupGraph = new NodeGroupGraph(Guid.NewGuid().ToString());

            nodeGroupGraph.name = name;

            nodeGroupGraph.nodes = gcopy.nodes;

            for (int i = nodeGroupGraph.nodes.Count - 1; i >= 0; i--)
            {
                var  n   = nodeGroupGraph.nodes[i];
                Node nod = nodesToGroup.Find(no => no.name == n.name);


                // node is not contained in the group => remove it from the grouped graph!
                if (nod == null)
                {
                    nodeGroupGraph.RemoveNode(n);
                }
            }

            foreach (var n in nodeGroupGraph.nodes)
            {
                foreach (var p in n.Ports)
                {
                    if (!p.IsConnected)
                    {
                        nodeGroupGraph.ports.Add(p);
                    }
                }
            }


            if (g is NTGraph)
            {
                NodeGroupGraph ngc = nodeGroupGraph.AddTo((NTGraph)g, nodesToGroup[0].position);

                for (int i = g.nodes.Count - 1; i >= 0; i--)
                {
                    Node n        = g.nodes[i];
                    var  nodeInNG = ngc.nodes.Find(no => no.name == n.name);

                    if (nodeInNG == null)
                    {
                        /*foreach(var port in n.Ports){
                         *  for (int c = port.ConnectionCount - 1 ; c >= 0; c--) {
                         *      NodePort other = port.GetConnection(c);
                         *
                         *      Node nodeInGroup = ngc.nodes.Find( no => no.name == other.node.name);
                         *
                         *      if(nodeInGroup != null){
                         *
                         *          Debug.Log("Redirect it to??? __ " + n.name);
                         *
                         *          port.Redirect(new List<Node>(){other.node}, new List<Node>(){nodeInGroup});
                         *      }
                         *  }
                         * }*/
                    }
                    else
                    {
                        foreach (var port in n.Ports)
                        {
                            for (int c = port.ConnectionCount - 1; c >= 0; c--)
                            {
                                NodePort other = port.GetConnection(c);

                                Node nodeInGroup = ngc.nodes.Find(no => no.name == other.node.name);

                                if (nodeInGroup == null)
                                {
                                    nodeInNG.GetPort(port.fieldName).Connect(other);
                                }
                            }
                        }

                        g.nodes.Remove(n);
                    }
                }
            }

            nodeGroupGraph.Export();

            return(nodeGroupGraph);
        }