Rewrite from scratch code