move creation of M_ to a separate file