cms: refactored code for readability.