More fixes from bent's review. New checks expose a bug (assert), will fix in future commit.