Clean up, documentation writing. Added more unit tests.