Fixed some of the memory leaks.
Removed some possible leaks.
Merge branch 'fix-memory-leak'