Factor out the different cases.