near-total rewrite