fix tests and refactoring