potential memory leaks fixed