Improve exception handling

TO BE UPDATED.