Please check the refactored code

Thanks