fix script to make idempotent