refs #41 - refactored and commented the code