Trying to fix memory leaks :(