Factor out common, repeated code.