some refactoring and fix of test fails