lots of logging refactoring