More work on testing.

- Add tests for public API.
- Add TODO test files for some other things.
- Fix some issues that were caught by the tests!