Clean up API, and beef up test coverage.