refactored code to look cleaner