Fixing memory leak problem.

Lets move this out of this scope as well