add some fixes for memory leaks