Refactored code to enhance readability and improve ease of maintainance.