Clean up the binding and add a tonne of docstrings

This is part of preparation for adding tests in the near future, and
probably running it through docutils as well.