Fix the generate grid bug