refactoring to ease unit tests
some regressions fix