Added Comments and refactored some code.