Hello I need help with making algorithm with the following:

Let's say a 2d domain of space with xmax, xmin, ymin, ymax, with 'n~10,000' of points in the space.

1. Go through lists of points positions.

2. When there is maximum no,of points (lets say 10) in the box, the box split into 4 equal smaller boxes.

3. Then check again if the each of the smaller box has more than maximum no. of points. it will split again into 4 equal smaller boxes.... until the box has less than the maximum no.of points per box.

Any suggestions how I can make this algorithm? Please?

Cheers!