Fix for memory leaks