VE-742 Some refactoring to simplify logic