Refactored logging