Fixes for #5252

Fixes for #5252 and refactoring. Perhaps you need to fix dc validation too. I did not watch it.