Solve some memory leaks