First total rewrite