added grid iteration code