* fixing idempotency and check mode * modified to avoid repetitive code (cherry picked from commit dcb35c4270)
dcb35c4270