Factor out some behavior into a protocol to make it marginally cleaner.