Fix bugs in mergeInputRecords