Code cleanup, additional test coverage.