compiled Afif's merge