fix failing tests and refactoring