Improve documentation and basic tidying of code.