refactoring some SM logic