Error handler: improved error handling