code with SM routines