Remove many redundant checks, and add a few new ones.