Commented and refactored code