Fixed memory leaks