Add docstrings, unit tests.