Refactored as per code review suggestion.