More refactoring and documentation.