Replaced ErrorMsg with real errors.