Refactor scm and pcom
fix conflicts
Mex file