refactored code for readability