Enhance doc generation 

some more refactorings