gen_grid improved