Refactored code based on code review