Factor out into a separate function. No functionality change.