Added tests for failures
Added functionality to handle failures