tidy up of the ifn function (which generates iteration functions)