More documentation and more refactoring