Improved exception handling