refactoring, tests
fixes