DYNAMO SCRIPT group curves

i have problem with script
i need to convert cad link rectangler to column when i run script to make groups for point it give me 12 point
put i need 4 point only to creat curve and finaly create the column iam beginner in dynamo so i need help

def grpCrvs(crv:var)
{
dis1 = (crv.StartPoint)<1>.DistanceTo(crv<2>)==0
||(crv.EndPoint)<1>.DistanceTo(crv<2>)==0;
ind1 = DSCore.List.AllIndicesOf(dis1<1>,true);
bln1 = true;
ind2 = [Imperative]
{
while (bln1)
{
cnt1 = DSCore.List.Count(ind1);
ind1 = grpIndx(ind1);
cnt2 = DSCore.List.Count(ind1);
bln1 = cnt2!=cnt1;
}
return = ind1;
}
crv1 = DSCore.List.GetItemAtIndex(crv,ind2);
return = crv1;
};

def grpIndx(ind:var[]..[])
{
	ind1 = DSCore.List.SetIntersection(ind<1>,ind<2>);
	cnt1 = DSCore.List.Count(ind1<1><2>)>0;
	ind2 = DSCore.List.FilterByBoolMask(ind,cnt1<1>)["in"];
	ind3 = DSCore.List.UniqueItems(ind2<1>);
	ind4 = DSCore.List.UniqueItems(DSCore.List.Flatten(DSCore.List.Sort(ind3<1>)<1>,-1));
	return = ind4;
};