make sure to reset state after error.