additional tests and some refactoring, add logging