refactored code to be more readable