Fixed the replace function-- hopefully the last time!