function for SM working
little refactor