fixed a lot of memory leaks