Memory leaks fix