Improve documentation and some cosmetic refactoring.