loop through grids to prevent memory overloading