Solid Intersection not working creating just recreating one solid

Hi,

I am trying to create a function that creates a series of random cubes on any surface, I have it most the way there but on some seeds it appears that some geometries go missing or that the solid i am using to crop the new shapes onto the surface is just being recreated i cant understand why its behaving like this. files attached any healp appreciated

random box curve WIP.gh (22.9 KB)
test.3dm (137.1 KB)