This code is about merging matrices