Fixes for memory leaks