Fix bug, improve logging.