Add docstrings and doctests