tests fixed, refactoring