fix regressions tests errors and code refactoring