Fixing replace function