improved logging logic: less space, less repetition