Optimized the error handling