added capability of writing multiple stage and sd matrices. also fixed a problem with recording names of sd matrices