New verion of wrapper that addresses a bug in error handling