refactored code for easier readability