half-granrew's algorythm r_mode switch