some refactorings, unit tests work