refactoring and fix tests