Fix excessive memory usage