refined error handler