Refactored code to make it more expressive