Fix bugs in sanity-checking code.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>