adding doxygen to document cpp; refactoring