Added comments, refactored code.