Fixing catastrophic memory leak bug