More refactoring and cocumentation