unified F2M function, see issue #7