rewrite (not complete)