Almost full rewrite from 0