move cleanup to save function