Fixed potential memory leaks