Near-total rewrite