tests, some refactoring