added some doc, minor refactoring