More refactorings and documentation