fixed several bugs in m conversion