Fix handling of very large datasets