More robust handling of failure cases.