large-scale rewrite