Improvements to exception handling