added diagnostic logging.