modified smj.cpp