Fixed bugs in quantization.