now averages over nans correctly