xml docs and some minor refactoring