Refactored as per given review.