Fix replacement function