replacement works by writing to new file