fix rewrite-existing bug