optimize  applypatch