rewrite from SCRATCH: