Optimize for large result sets

Fetch in batches to avoid consuming all available memory when dealing
with large result sets.
Merge branch 'develop-fftf'