Improve exception catching