fix replace function which became broken.

Fixing error throw when replacing an image.