Adjusted replacement strategy to maintain script dependencies