rewrite switch mode code;