Refactored code to mke it more readable