Migrated utils from ch_analysis and driftscan.