refactoring and logging