change: fix bugs in creating matrix