Fix #16504

This is a deep fix, we need to test it thoroghly