Fix re-running finalize phase

We need to reset the states on the finalize phase before running it
because we run the finalize only when there were no steps in error state.

Also because the finalize runs in transaction, we rerun also finished
finalize steps.