Remove some dead code, improve some asserts, and other assorted changes. No functionality change.