Simplify error handling code