fix syntax errors in merging function