Fixing replace bug