Reworking _clean_data() to be smarter about replaces

Fixes #8228