Make quantization code more portable