More docstrings and tidy-ups.