Fixes some memory leaks