adding save function for switching machines