added better error reporting for sanity check, and fixed typo