Merge adjacent nodes with the same record