Added tests, and fixed bugs that were found in code and documentation via the tests.