Improve replace script