more general version of 'emx' function.