Fixes for bugs discovered by new tests.