Working out the logic behind laying out the grid.