Refactored as per review.