TDI-30715:fix TDI-30715 and TDI-30521 together and improved some code.
Merge branch 'maintenance/5.6'