fixed memory leak for large datasets