Updated quantize function