added security check to replacing images