Simplify some code and increase test coverage.