More refactorings relating to grid_shape.