Fix trans of calls to foreign fns. Refactoring

Fixes #15913