Attempted fix for issue #7.

Also added more detailed logging.