Refactored and simplified.