Cleanup a bit.
Add some unit tests.