Factor out preprocessing