Fixing replacement function