quick bug fix.  Also added some logging.