more tests, refactor and log messages