refactored and documented all the sourcecode