Improve documentation and add some unittests.