Documentation and minor refactorings