Refactored code after code review