rewrite and improve