Minor fix to error handling