Added docstrings to non-trivial functions.