Clean up source files.
Add unit tests and fix minor bugs.