Attmepted to improve exception handling