Fixes mem leaks.
Resolving memory leaks.