Improvements to error handler