Fixed up according to our rule that `data` is non-null iff `stats` is non-null, but please double-check the logic again after I commit :)