improving error handler