simplify error handling code flow