rewrite from scratch