Fix validation bugs and tests.