fixed a bug in m replacement