fixed up merging code