First part of the function - until grid.density.obj