More documentation and refactoring.