Tested working for n dimensions.
Tested with 100000 points in 10 dimensions