small bug fixes, improved logging.