Sped up merging code