Improve idempotence of script