[OE-3987] refactoring and unit tests