Some minor fixes

fixed a small memory leak and a crash