Tidied up code and documentation.