Second attempt in fixing memory leak