Refactored to avoid circular dependencies.