You should probably extract the "for (Plane p....){}" block into a function. You can also use that function above (in the doRandomDSAStep part).