Fixing massive memory leak