adjusted calculation of grid size