Factor out some more code duplication