functions and gives equivalent results to old clustering on electron gun, 2-4 times faster