Refactored code for better maintainability.