refactor for idempotence check