Memory leaks fixes