put save inside if block