Separated logic for dry-run and commit.