Cleaned up error handler