rewrite from the beginning