revise comments and adding SM function optimizing