Add docstrings

An attempt to improve the coverage of documentation on all functions.