AG-4391: initial refactoring