Refactored code to make it look cleaner