Added more sophisticated logging.