[TIDOC-931] Rework some code