Refactoring logging and adding more tests.