fix lot of memory leaks