Added better handling of failures