Use generators to avoid memory consumption.