some memory leaks fixing