Panelization/Space frame by nodes

So I’m trying to create an approximate framing of a surface based on the number of nodes input into the surface. The goal is to create a frame structure with four members per node. However, i’m having problems with having each node have the requisite number of connections. As a quad panel, each node should have 4 connections, and i’m trying to determine which nodes connect to which through the closestpoint function, but am not sure how to ensure that each node has only 4 connectors, with no duplicates.

Help appreciated, script is attached. Surface Framing (13.1 KB)