fixed off-by-one in grid layout