some memory leaks fixed