Fix and add test on grid generation. Now solve problem described in spec.