Fix more bugs found by unit tests.