logging and refactoring