Add logging.
Bug fixes.