Cleaned up code in error handler