Add comments and robustify error logging.