Extracted duplicated script fixing logic to a private method