[TIDOC-1487] Refactor and reformat code