Tidied things up considerably. Mostly docstrings remaining.