Refined and refactored code.