serial version of mf.cpp