Fixed bug in error handler