Clean up and improve logging.