Update replacement logic when function found and remove context flag.