Dominic: rewrite coalescing algorithm in recursive style