Added template cleanup code.