Refactored sanitizeTreeReadOnly