Fixing memory leaks on rerun.