Refined logging messages. Added safety check.