fix handling of errors