Corrected error handling