Tried to fix memory leaks.