Minor tweaks to fix memory leaks discovered by profiler.