Refactored as per review suggestions.