corrected error handling