improvement in replace_collection script
script improved