updated the code to capture on fail