A rewrite of emod.