added doxygen documentation and cleaned up the code, no changes to behavior