More refactoring and documenting