Refactored code to be more clear