Updated test suite to improve coverage, and code to improve testability.