fix some memory leaks