[#62628522 #61529740] refactoring, couple of bugfixes and test fixes