More work on documentation and minor refactoring