Bug fixes, update documentation, add unit tests.