More refined backport of CRM.API