added generate grid function