Some documentation and refactoring.