Code refactored and Doxygen doc comments added.