Folding code moved to quant_band() to prevent duplication.