Refactored code and wrote some documentation.