OAK-1561 refactored and optimised the code preparing the ground for OAK-1570