fix potential memory leaks