Documentation and some Refactoring