refactored log method