Factor out recompute logic to a helper