Fixed memory leaks
Merged