Properly calculate the grid.