implement head merging