Fixes memory usage bottleneck