clean up duplicate code and make sure cluster state is correct
in failure cases.