[R40] Refine autopatch. Fix bug.