Fixing some bad logic.

And finding other stuff that doesn't quite work right.